Slide 1

Slide 1 text

ϚΠΫϩαʔϏε microservice #hatenaintern2021

Slide 2

Slide 2 text

泘㗧 • microservice • Ͳ͜Ͱ microservice Λ㒻㕴͢Δ͔? • microservice chassis • Մ᧺ଌੑ (observability) • service 㕽㙳৴ • 㒻ࢄ data ؅ཧ • micro frontend • microservice ͷ release

Slide 3

Slide 3 text

NJDSPTFSWJDF .

Slide 4

Slide 4 text

NJDSPTFSWJDF micro + service

Slide 5

Slide 5 text

NJDSPTFSWJDF micro + service micro- : খ͞ͳ

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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)]

Slide 10

Slide 10 text

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)]

Slide 11

Slide 11 text

TFSWJDF ྫ :

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

TFSWJDF service ͷதͰ͸ᒬʑͳ process (OS process, goroutine, OOP class instance, etc.) ͕ಈ͍ͯΙΔ [ଞͷ process ͔Βͷೖྗ] <-(ܭࢉ΍ख᠃͖)- [process = (service)]

Slide 18

Slide 18 text

TFSWJDF OOP class instance Λ "service" ͱݺͿྫ cf. PoEAA p.133, p.139 "Service Layer"

Slide 19

Slide 19 text

TFSWJDF service ͷதͰ͸ᒬʑͳ process (OS process, goroutine, OOP class instance, etc.) ͕ಈ͍ͯΙΔ [ଞͷ process ͔Βͷೖྗ] <-(ܭࢉ΍ख᠃͖)- [process = (service)]

Slide 20

Slide 20 text

TFSWJDF service ͷೖΕࢠ͕㒁ʹ᠃͘৔߹΋͋Δ

Slide 21

Slide 21 text

TFSWJDF service ͷதʹ service ͕͋ͬͯɺதͷ service ͕ deploy ͢ΔᄸҐͰ΋͋Δ৔߹ɺதͷ service Λ microservice ͱݺͿ

Slide 22

Slide 22 text

TFSWJDF Q. ͜Ε͸ service Ͱ͔͢?

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

TFSWJDF [user ͷٻΊ] <-(෺ࣄΛఏڙ͢Δ)- [࢓૊Έ (= service)] user ͱ࢓૊Έ͸نଇ (protocol) ʹኺͬͯ΍ΓऔΓ͢Δ ྫ : • menu ʹԊͬͯḼ亣͠୅ۚΛ፫; <- 㘆඼Λ㗵͚౉͢ • HTTP request <- HTTP response

Slide 26

Slide 26 text

TFSWJDF microservice ͷ㑔ޠ : SOA (service oriented architecture)

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

TFSWJDF Q. ͜Ε͸ service Ͱ͔͢? .

Slide 30

Slide 30 text

TFSWJDF Q. ͜Ε͸ service Ͱ͔͢? A. ͍͍͑ɻ͜Ε͸ service Ͱ͸͋Γ·ͤΜɻuser ͱ࢓૊Έ͸نଇ (protocol) ʹኺͬͯ΍ΓऔΓͯ͠Ι·ͤΜ

Slide 31

Slide 31 text

TFSWJDF user ͱ࢓૊Έͷ㕽ʹ͸௨৴࿏͕͋Δ

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

NPOPMJUI service 㚎ͷ process ΍ OOP class instance ͕ɺଞͷ process ΍ OOP class instance Λ user ͱͯ͠෺ࣄΛఏڙ ͯ͠ΙΕ͹ɺ͜ΕΒ΋ service ͱݟ၏ͤΔ Ͱ͸ process ͸ microservice Ͱͤ͏͔?

Slide 37

Slide 37 text

NPOPMJUI microservice ʹԙ͚Δݸʑͷ service ͸ deploy ᄸҐ • ᘐཱʹ deploy ͢ΔͷͳΒ microservice • వΊͯ deploy ͢ΔͳΒ monolith ઃܭʹ͸ microservice ͱ monolith Ͱಉ͡ख๏͕㒊΁ΔɻಘΒΕΔᏈՌ΋ࣅΔ ྫ : refactoring (㘟㕡㙹 architecture)

Slide 38

Slide 38 text

ל׆ךNJDSPTFSWJDF؅㒻׌׾־ .

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

CVTJOFTTDBQBCJMJUZס㗞 ྫ : • 㚒ᨽ • 㘆඼දࣔɾᒾࡧ • ՝ۚ • ग़ՙ

Slide 42

Slide 42 text

CVTJOFTTDBQBCJMJUZס㗞 [user ͷٻΊ] <-(෺ࣄΛఏڙ͢Δ)- [࢓૊Έ (= service)] business capability ͷڥ = user ͷٻΊΔ෺ࣄͷڥ • user ͕ҟͳΔ • user ͸ಉ͕ͩ͡ٻΊΔ෺ࣄ͕ҟͳΔ

Slide 43

Slide 43 text

CVTJOFTTDBQBCJMJUZס㗞 ʮservice Λ㒻͚ΔͳΒ team Λ㒻͚Δʯ͔?

Slide 44

Slide 44 text

CVTJOFTTDBQBCJMJUZס㗞 Conway ͷ๏ଇ : service ͷ㗇㙉͸૊৫ͷ㗇㙉ʹኺ; cf. Melvin E. Conway "How Do Committees Invent?" 1968

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

CVTJOFTTDBQBCJMJUZס㗞 1. team ⇭ͷ communication ͸ team ⤨Ƒ communication ΑΓࠔ㐾Ͱ͋Δ service ΛᏓ㒁͢Δࡍͷ team 㕽 communication ʹ͸ɺ • service ͷڞ༗ (Ꮣ㒁͕ࣗݾ׬݁͠ͳ͍) • ਓͷڞ༗ (݉຿)

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

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

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

CVTJOFTTDBQBCJMJUZס㗞 ʮservice Λ㒻͚ΔͳΒ team Λ㒻͚Δʯ͸ɺҎ্ͷ cost ⃧ݮʹ᮫ͯ͠亯㙺ͳͱ͜ΖΛݟෟ͚ͯߦ; Q. 亯㙺? A. service શᱪΛΑ͘ɺૉૣ͘Ꮣ㒁͠᠃͚ΔࣄΛ໨ࢦ͢ ཧ༝ 2 ͷղܾࡦ (SRE (site reliability engneering)) ɺཧ༝ 3 ͷղܾࡦ (CD (៺᠃㙹 delivery / deploy)) ΋ಉᒬʹɺ cost ⃧ݮʹ᮫ͯ͠亯㙺ͳͱ͜ΖΛݟෟ͚ͯߦ;

Slide 55

Slide 55 text

TDBMBCJMJUZס㗞 scaling • scale up : ߴ͍ੑೳͷ server Λ㒊; <-> scale down • scale out : server ͷᢕᏐΛ⃧΍͢ <-> scale in

Slide 56

Slide 56 text

TDBMBCJMJUZס㗞 Kubernetes ͷ pod ͩͱɺ • scale up : VPA (vertical pod autoscaler) • scale out : HPA (horizontal pod autoscaler)

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

TDBMBCJMJUZס㗞 x ࣠ : ಉ͡ service Λ ಉ͡໾㕴Ͱ deploy ͢Δ (scale out)

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

TDBMBCJMJUZס㗞 z ࣠ : ಉ͡ service Λ deploy ͢Δ͕ɺdeploy ͢Δ server 㑌ʹҟͳΔ໾㕴Λ፦͸ͤΔ

Slide 62

Slide 62 text

TFDVSJUZס㗞 㘒ใ security ͷࡾ㛿ૉ • C : 㖇ີੑ (confidentiality) • I : ׬㙂ੑ (integrity) • A : Մ༻ੑ (availability)

Slide 63

Slide 63 text

TFDVSJUZ㖇㳡䓪 DPOEFOUJBMJUZ ס㗞 access ੍ޚ • AWS IAM • Kubernetes ͷ ServiceRoleɺClusterRole • OPA (open policy agent)

Slide 64

Slide 64 text

TFDVSJUZ㱭㙂䓪 JOUFHSJUZ ס㗞 • DB ͷ㒻཭ • service 㕽㙳৴ͷ㕆ᥒ㕡

Slide 65

Slide 65 text

TFDVSJUZ⺎榫䓪 BWBJMBCJMJUZ ס㗞 ো᛻Λ೾㖎ͤ͞ͳ͍ • fault tolerance • API rate limit • circuit braker ো᛻͔Β伭෮͢Δ • auto healing • back pressure

Slide 66

Slide 66 text

NJDSPTFSWJDFDIBTTJT .

Slide 67

Slide 67 text

NJDSPTFSWJDFDIBTTJT chassis : γϟʔγɻ࿮૊Έ ͲΜͳ microservice ʹ΋㛿ΔɺԣᏗ㙹ͳ᮫৺ࣄ (cross cutting concern) Λመ᧋͢Δ a.k.a. framework

Slide 68

Slide 68 text

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

Slide 69

Slide 69 text

NJDSPTFSWJDFDIBTTJT ͲΜͳ microservice ʹ΋㛿ΔɺԣᏗ㙹ͳ᮫৺ࣄ (cross cutting concern) Λመ᧋͢Δ መ᧋ྫ : • Sprint Boot + Spring Cloud • nytimes/gizmo

Slide 70

Slide 70 text

⺎鈴峮䓪 PCTFSWBCJMJUZ .

Slide 71

Slide 71 text

⺎鈴峮䓪 PCTFSWBCJMJUZ service ͷᕝ͍ͨͨ͠ੑ࣭ : • Մ᧺ଌੑ (observability) : ᧺ଌ͔Β service ͷ㐫ଶΛਪଌͰ͖Δ • Մ੍ޚੑ (controllability) : service Λ㛕Ή㐫ଶʹᏓ㒁Ͱ͖Δ • ҆ఆੑ (stability) : service ͷ㐫ଶ͸Ұఆͷൣᅴʹཹ·Δ

Slide 72

Slide 72 text

⺎鈴峮䓪 PCTFSWBCJMJUZ Մ᧺ଌੑͷࡾ㚋㖥 : • metric (ྫ : Prometheusɺ Mackerel :-)) • tracing (APM (application performance monitoring)ɺ㒻ࢄ tracing) • logging (㗇㙉㕡 logɺहूɺ㒻ੳ)

Slide 73

Slide 73 text

TFSWJDF㕽㙳⟓ .

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

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

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

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

Slide 80

Slide 80 text

TFSWJDF㕽㙳⟓ ઌʹنଇ (protocol) ΛܾΊΔͱɺ㙳৴ઌͷ service Λᔅʹͤͣ։ᚙͰ͖Δ => schema first schema first ʹ͢Δͱɺ • ։ᚙ㐥㕽ͷ communication cost ͕Լ͕Δ • schema Λ㒊ͬͯ test Ͱ͖Δ schema ͸㛿ٻ service ͱఏڙ service ͷڞ༗ࢿݯ (ཧ༝ 3 : ڞ༗ࢿݯͳͷͰ CD (៺᠃㙹 delivery) ͢Δͷ͕㛕·͍͠)

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

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))) •

Slide 85

Slide 85 text

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

Slide 86

Slide 86 text

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

Slide 87

Slide 87 text

TFSWJDFNFTI service ͸ଞͷ service ͱ㙮઀㙳৴͠ͳ͍ɻ㕽ʹ proxy ͕ೖΓɺproxy ͕㙳৴Λ᧺ଌɾ੍ޚ͢Δ Q. proxy ࣗᱪ͸ container Ͱಈ͘ඞ㛿͕͋Γ·͔͢? A. ͍͍͑ɻመࡍͷ network 㖇ೳ΍ topology Λந৅͠౷Ұ㙹ʹ᧺ଌɾ੍ޚͰ͖Ε͹ཧ࿦্͸ɺΑΓ native ͳ software ΍ kernel ΍ bare metal Ͱመ᧋͢Δࣄ΋ՄೳͰ͢ɻSDN (software defined networking) ͸ͦͷࢼΈͱ΋ ݴ΁·͢

Slide 88

Slide 88 text

TFSWJDFNFTI መ᧋ྫ : • Istio • Consul Connect (on Nomad) • Linkerd

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

*TUJP • data plane : Envoy proxy • control plane : istiod

Slide 91

Slide 91 text

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

Slide 92

Slide 92 text

*TUJP • data plane Λ㗇㙡͢Δ : sidecar injection

Slide 93

Slide 93 text

*TUJP • data plane Λઃఆ͢Δ : Envoy ͷઃఆΛ࡞Γɺઃఆ͢Δ • data plane ͔Βͷ໰ͻ߹͸ͤʹ౴΁Δ : ઃఆʹදͤͳ͍ Envoy ͷ੍ޚ

Slide 94

Slide 94 text

*TUJP • data plane Λ᧺ଌ͢Δ : Մ᧺ଌੑ (observability)

Slide 95

Slide 95 text

㒻丆EBUB畘杼 .

Slide 96

Slide 96 text

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

Slide 97

Slide 97 text

㒻丆EBUB畘杼 software = data + ႔ཧ data ͷ㕅ͻ͸ read ͱ write ʹ㒻͚ΒΕΔ (cf. CQRS (command query ੹຿㒻཭)) • read : [microservice] <-(data ΛᩇΈग़͢)- [microservice] • write : [microservice] <-(data Λอଘͤ͞Δ)- [microservice]

Slide 98

Slide 98 text

㒻丆EBUB畘杼SFBE read : [microservice] <-(data ΛᩇΈग़͢)- [microservice] • API composition • materialized view • ڞ༗ DB

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

㒻丆EBUB畘杼SFBE API composition ࣅͨख๏ : • API gateway : API composition Λߦ;ሢ༻ͷ microservice • BFF (backend for frontend) : ಛఆͷ frontend ޲͚ͷ API gateway

Slide 101

Slide 101 text

㒻丆EBUB畘杼SFBE materialized view ᩇΈऔΓሢ༻ͷ view Λ࡞Δ ʮmicroserviceʯಉ࢜͸ີ݁߹ɻಉ͡ team ͕ᩇΈ / 㘃͖ၷํͷ microservice Λ㘂༗͢ΔͳΒ㓂ར

Slide 102

Slide 102 text

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

Slide 103

Slide 103 text

㒻丆EBUB畘杼XSJUF write : [microservice] <-(data Λอଘͤ͞Δ)- [microservice] • event sourcing • TCC (try-confirm / cancel) • saga • ڞ༗ DB

Slide 104

Slide 104 text

㒻丆EBUB畘杼XSJUF event sourcing 㐫ଶΛᏓ㒁 event ͷूੵͱͯ͠ද͸͢ɻmessage broker ͷՄ༻ੑ͕ߴ͚Ε͹ɺ֤ service ͷো᛻ʹӨ伖͞Εʹ ͍͘

Slide 105

Slide 105 text

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

Slide 106

Slide 106 text

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

Slide 107

Slide 107 text

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

Slide 108

Slide 108 text

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

Slide 109

Slide 109 text

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

Slide 110

Slide 110 text

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

Slide 111

Slide 111 text

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

Slide 112

Slide 112 text

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

Slide 113

Slide 113 text

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

Slide 114

Slide 114 text

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

Slide 115

Slide 115 text

㒻丆EBUB畘杼XSJUF saga ׬݁ͨ͠ transaction Λ૊Έ߹͸ͤͯෳᏐͷ DB ΛᏓ㒁͢Δ • choreography based saga • orchestration based saga

Slide 116

Slide 116 text

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

Slide 117

Slide 117 text

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

Slide 118

Slide 118 text

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

Slide 119

Slide 119 text

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

Slide 120

Slide 120 text

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

Slide 121

Slide 121 text

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

Slide 122

Slide 122 text

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

Slide 123

Slide 123 text

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

Slide 124

Slide 124 text

㒻丆EBUB畘杼 CAP ఆཧ : ҎԼͷࡾᑍ݅Λಉ࣌ʹ׬શʹ㙘㘫Ͱ͖ͳ͍ • Ұ؏ੑ (consistency) • Մ༻ੑ (availability) • network 㒻Ꮧ଱ੑ (partition tolerance) BASE : ෦෼తʹͰ͋Ε͹ CAP ͸ಉ࣌ʹ㙘㘫Ͱ͖Δ (<-> ACID (ݪࢠੑ (atomicity)ɺҰ؏ੑ (consistemcy)ɺᘐཱੑ (isolation)ɺӬ᠃ ੑ (durability))) • Basically Available • Soft-state • ݁Ռ੔߹ੑ (Eventually consistent)

Slide 125

Slide 125 text

NJDSPGSPOUFOE .

Slide 126

Slide 126 text

NJDSPGSPOUFOE microservice Λ։ᚙ͢Δ team ͕ɺ֘ᙛ͢Δ frontend ΋։ᚙ͢Δ ͍҃͸ business capability ʹԊͬͯ frontend ͚ͩ㒻㕴ͯ͠͠·; < microservice Ͱߦͬͨͷͱಉٞ͡࿦

Slide 127

Slide 127 text

NJDSPGSPOUFOE 㒻㕴ख๏ : • page 㙂ᱪΛఏڙ͢Δ (route-based code splitting) • component Λఏڙ͢Δ (ྫ : React componentɺCSS in JSɺCSS Module) • error ͸ด͡㗓ΊΔ

Slide 128

Slide 128 text

NJDSPGSPOUFOE㕽㙳⟓ • frontend ಉ࢜͸㙳৴ͤͣɺbackend Λհ͢Δ • URL ͷ query string Λհ͢Δɻpage ͕㒻͔ΕͯΙΔͳΒ༗༻ • property Λհͯ͠౉͢ (ྫ : React propertyɺDOM attribute) • event emitter • 㐫ଶΛڞ༗͢Δ (ڞ༗ DB ͱಉ͡ࠔ㐾Λ᧷ޛ͢Δ) (ྫ : Redux Λڞ༗)

Slide 129

Slide 129 text

NJDSPGSPOUFOE 㒻㕴ͨ͠΋ͷΛ഑৴͢Δख๏ : • 㙂͘ҟͳΔ Web site ͱͯ͠㗇㙡͢Δ • bundling (ྫ : Webpack) • backend Ͱ૊Έ߹͸ͤΔ (ྫ : SSI (server-side includes)ɺESI (edge-side includes)) • lazy load (ྫ : loadable-componentsɺdynamic import)

Slide 130

Slide 130 text

NJDSPGSPOUFOE backend ։ᚙͱ frontend ։ᚙͰҟͳΔ㒻㕴Λߦ;ͳΒɺ => BFF (backend for frontend) : ಛఆͷ frontend ޲͚ͷ API gateway

Slide 131

Slide 131 text

NJDSPTFSWJDFסSFMFBTF .

Slide 132

Slide 132 text

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

Slide 133

Slide 133 text

NJDSPTFSWJDFסSFMFBTF release Λࡾͭʹ㒻͚Δ : build + deploy + release • canary release • B/G (Blue/Green) deloyment • feature toggle

Slide 134

Slide 134 text

NJDSPTFSWJDFסSFMFBTF canary release Ұ෦ͷ user ʹઌߦͯ͠ release ͢Δ

Slide 135

Slide 135 text

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

Slide 136

Slide 136 text

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

Slide 137

Slide 137 text

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

Slide 138

Slide 138 text

NJDSPTFSWJDFסSFMFBTF 㒻ࢄ system Ͱ͸೗ԿͳΔ release खॱͰ΋ɺ2 version ͕ᝀཱ͠͏Δ ሣࡦ : • ޙํޓ׵ੑΛอͭ • API versioning ʹͯ৽ API Λᢜ client ͔Β੾Γ཭͢ • error budget ΛఆΊɺerror Λڐ༰͢Δ • fronend ౳ cache ͷڧ੍ purge Λመ᧋͢Δ

Slide 139

Slide 139 text

׷זיײ׷ֹסؤ٭ػ٭մ㡎״ױ׌ נ٭

Slide 140

Slide 140 text

׷זיײ׷ֹ*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 ʹ ͳͬͯΙΔ͜ͱΛ֬㚒͠·͢

Slide 141

Slide 141 text

׷זיײ׷ֹ*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

Slide 142

Slide 142 text

,JBMJ

Slide 143

Slide 143 text

׷זיײ׷ֹ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 ͷ㙟Λ֬㚒͠·ͤ͏

Slide 144

Slide 144 text

׷זיײ׷ֹGBVMUJOKFDUJPO • renderer service Λɺਖ਼ৗʹಈ࡞͢Δ͕ɺresponse ͕ 5 ඵᬌΕΔ㐫ଶʹ͍ͯͩ͘͠͞ • Kiali Ͱ application ͷ㐫ଶΛ֬㚒͠·ͤ͏ • istio-proxy ͷ log ͷ response_flags Λ֬㚒͠·ͤ͏ • kubectl delete virtualservices.networking.istio.io [໊㙁] Ͱ fault injection Λղআ͠· ͤ͏

Slide 145

Slide 145 text

㒁מ㱃שמע 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