Slide 1

Slide 1 text

DJSDVJU_TXJUDI 
 ͍ͪ࢝͘͞ΊΔHFNͮ͘Γ 2021.10.10. Kaigi on Rails _2021_ new @makicamel

Slide 2

Slide 2 text

w!NBLJDBNFM઒ݪສق w3VCZͱϏʔϧɹɹͱ͓ञ͕޷͖ w޷͖ͳ73ήʔϜ ࣗݾ঺հ

Slide 3

Slide 3 text

࠷ۙࠔ͍ͬͯΔ͜ͱ ͓࢓ࣄͰ

Slide 4

Slide 4 text

ো֐͕ଟ͍

Slide 5

Slide 5 text

•ӨڹൣғௐࠪΛ͕Μ͹Ζ͏ •ϨϏϡʔΛ͕Μ͹Ζ͏ •ࣗಈςετͷ௥ՃɾϝϯςΛ͕Μ͹Ζ͏ •खಈςετΛ͕Μ͹Ζ͏ •Τϥʔ؂ࢹΛ͕Μ͹Ζ͏ ো֐Λىͨ͜͠ਓྨͷߟ͕͑ͪͳ͜ͱ ΋ͬͱ ΋ͬͱ ΋ͬͱ ΋ͬͱ ΋ͬͱ

Slide 6

Slide 6 text

͕Μ͹Γͨ͘ͳ͍

Slide 7

Slide 7 text

•͕Μ͹ΔͱϛεΔ •͕Μ͹Γ͸ݸਓʹґଘ •͕Μ͹ΔͱർΕΔ •͕Μ͹Δ͸Ӭԕʹ͸ܧଓͰ͖ͳ͍ ͕Μ͹Γͨ͘ͳ͍

Slide 8

Slide 8 text

࢓૊ΈͰͳΜͱ͔͍ͨ͠

Slide 9

Slide 9 text

ɹো֐͕ଟ͍ΜͰ͢Α…😣 ɹ90% ϛε͕ͳ͍͜ͱͷอূ͸ͦͦ͜͜Ͱ͖Δ͚Ͳ 
 ɹ100% ϛε͕ͳ͍͜ͱͷอূ͸ͱͯ΋ߴίετ ɹϦϦʔεස౓Λ্͛Δͷ͕೉ͯ͘͠…😭 ɹ͙͢ʹ੾Γ໭ͤΔΑ͏ʹͨ͠ํ͕ 
 ɹ݈શ͔΋͠Ε·ͤΜͶ

Slide 10

Slide 10 text

•ϦϦʔε͸िʹ 1 ճ ˞ 
 ˞ো֐ରԠΛআ͘

Slide 11

Slide 11 text

•ϦϦʔε͸िʹ 1 ճ •100ʙ200 Pull Requests •500ʙ1,000 commits •10Kʙ60K lines ˞ ϏοάόϯϦϦʔε 
 ˞Ұ൪ݹ͘ػೳ͕ଟ͍ϞϊϦγοΫϦϙδτϦʹ͓͚Δ਺ɻଟ͘ͷଞϦϙδτϦ͸΋ͬͱԺ΍͔Ͱ͢ 
 ˞ো֐ରԠΛআ͘ ˞

Slide 12

Slide 12 text

ϦϦʔείετ͕ߴͯ͘ো֐͕ଟ͘ɾେ͖͘ͳΓ͕ͪ ো֐͕ଟͯ͘ϦϦʔεස౓Λ্͛ΒΕͳ͍ ϏοάόϯϦϦʔε

Slide 13

Slide 13 text

ͱ͍͏Θ͚Ͱ

Slide 14

Slide 14 text

ͭͬͨ͘ NBLJDBNFMDJSDVJU@TXJUDI 
 IUUQTHJUIVCDPNNBLJDBNFMDJSDVJU@TXJUI

Slide 15

Slide 15 text

circuit_switch

Slide 16

Slide 16 text

ɹো֐͕ଟ͍ΜͰ͢Α…😣 ɹ90% ϛε͕ͳ͍͜ͱͷอূ͸ͦͦ͜͜Ͱ͖Δ͚Ͳ 
 ɹ100% ϛε͕ͳ͍͜ͱͷอূ͸ͱͯ΋ߴίετ ɹϦϦʔεස౓Λ্͛Δͷ͕೉ͯ͘͠…😭 ɹ͙͢ʹ੾Γ໭ͤΔΑ͏ʹͨ͠ํ͕ 
 ɹ݈શ͔΋͠Ε·ͤΜͶ

Slide 17

Slide 17 text

circuit_switch ΍Γ͍ͨ͜ͱɿ ϦϦʔεස౓Λ͋͛Δ 
 ˞ϦϦʔεස౓΋͍͋͛ͨͰ͢

Slide 18

Slide 18 text

circuit_switch ΍Γ͍ͨ͜ͱɿ ௿ίετʹ੾Γ໭͢

Slide 19

Slide 19 text

circuit_switch if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end CircuitSwitch.report(if: unexpected_happen)

Slide 20

Slide 20 text

circuit_switch if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end

Slide 21

Slide 21 text

circuit_switch •CircuitSwitch ͕։͍͍ͯΔ࣌ do_something_experimental ΛݺͿ •CircuitSwitch ͕ด͡ΒΕͨ࣌ call_existing_codes ΛݺͿ if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end

Slide 22

Slide 22 text

circuit_switch •CircuitSwitch ͷ։ด৚݅ نఆ্ݶճ਺ʹ౸ୡ ։์৚݅ͱҰக ด࠯৚݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด࠯

Slide 23

Slide 23 text

circuit_switch •CircuitSwitch ͷ։ด৚݅ if CircuitSwitch.open?(reach_limit: 100) do_something_experimental else call_existing_codes end نఆ্ݶճ਺ʹ౸ୡ ։์৚݅ͱҰக ด࠯৚݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด࠯

Slide 24

Slide 24 text

circuit_switch if CircuitSwitch.open?(if: current_user.testing?) do_something_experimental else call_existing_codes end •CircuitSwitch ͷ։ด৚݅ نఆ্ݶճ਺ʹ౸ୡ ։์৚݅ͱҰக ด࠯৚݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด࠯

Slide 25

Slide 25 text

circuit_switch if CircuitSwitch.open?( close_if: Date.today > some_period ) do_something_experimental else call_existing_codes end •CircuitSwitch ͷ։ด৚݅ نఆ্ݶճ਺ʹ౸ୡ ։์৚݅ͱҰக ด࠯৚݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด࠯

Slide 26

Slide 26 text

circuit_switch rake circuit_switch:terminate_to_run 
 [/app/services/greetings_service:21 block 
 in validate] •CircuitSwitch ͷ։ด৚݅ if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end نఆ্ݶճ਺ʹ౸ୡ ։์৚݅ͱҰக ด࠯৚݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด࠯

Slide 27

Slide 27 text

circuit_switch CircuitSwitch.report(if: unexpected_happen) •CircuitSwitch ͕։͍͍ͯΔ࣌ report ΛૹΔ •Slack ΍ Bugsnag ͳͲ೚ҙͷϨϙʔτπʔϧΛࢦఆ •։ด৚݅͸ open? ͱྨࣅͷ৚݅Λࢦఆ

Slide 28

Slide 28 text

circuit_switch •ґଘϥΠϒϥϦ •ActiveRecord •࣮ߦߦʢcallerʣɾCircuitSwitch ͷ։ดঢ়ଶΛ DB ʹอଘ •ActiveJob •DB ߋ৽ɾϨϙʔτ

Slide 29

Slide 29 text

circuit_switch •ίʔυϦʔμʔͷΈͲ͜Ζ

Slide 30

Slide 30 text

circuit_switch •ίʔυϦʔμʔͷΈͲ͜Ζ •ͳ͍

Slide 31

Slide 31 text

circuit_switch •ίʔυϦʔμʔͷΈͲ͜Ζ •ͳ͍ •ͳ͍ͷ͕ΈͲ͜Ζʢʁʣ

Slide 32

Slide 32 text

ΈͲ͜Ζ •Կ΋มΘͬͨ͜ͱΛ΍͍ͬͯͳ͍ •Rails ͷίʔυ͕ॻ͚ͨΒॻ͚Δ •ࠓ͙͢ॻ͖࢝ΊΒΕΔ

Slide 33

Slide 33 text

ΈͲ͜Ζ •;ͭ͏ͷ Rails ΞϓϦ͕ґଘ͍ͯ͠ΔϥΠϒϥϦʹґଘ •ࠓ͙͢ಋೖͰ͖Δ

Slide 34

Slide 34 text

ͱ͜ΖͰ͓ؾ͖͔ͮͱࢥ͍·͕͢

Slide 35

Slide 35 text

Inspired by •Feature Toggles •CircuitBreaker 'FBUVSF5PHHMFTNBSUJOGPXMFSDPN 
 IUUQTNBSUJOGPXMFSDPNBSUJDMFTGFBUVSFUPHHMFTIUNM $JSDVJU#SFBLFSNBSUJOGPXMFSDPN 
 IUUQTNBSUJOGPXMFSDPNCMJLJ$JSDVJU#SFBLFSIUNM

Slide 36

Slide 36 text

Feature Toggles •৽ػೳΛಛఆϢʔβʹ҆શɾ଎΍͔ʹఏڙ͢ΔͨΊͷ࢓૊Έ •ؔ࿈ɿDark Launch •🙅 େن໛ feature ϒϥϯν্Ͱͷ։ൃ 
 🙆 master(main) ϒϥϯνʹ߹ྲྀͨ͠։ൃ 'FBUVSF5PHHMFTNBSUJOGPXMFSDPN 
 IUUQTNBSUJOGPXMFSDPNBSUJDMFTGFBUVSFUPHHMFTIUNM

Slide 37

Slide 37 text

Feature Toggles •ΧφϦΞϦϦʔε •ϥϯμϜબग़ͷۃҰ෦ͷҰൠϢʔβʹػೳ։์༷ͯ͠ࢠݟ •A / B ςετ 'FBUVSF5PHHMFTNBSUJOGPXMFSDPN 
 IUUQTNBSUJOGPXMFSDPNBSUJDMFTGFBUVSFUPHHMFTIUNM

Slide 38

Slide 38 text

CircuitBreaker •αʔόʹಛఆճ਺Ҏ্ͷো֐͕ൃੜͨ࣌͠ʹ 
 ϦΫΤετΛड͚෇͚ͣʹΤϥʔΛฦ͢࢓૊Έ •ো֐ͷ࿈࠯తͳൃੜΛ๷͙ •αʔό͕վળͨ͠ΒࣗಈͰ෮ؼ͢Δ $JSDVJU#SFBLFSNBSUJOGPXMFSDPN 
 IUUQTNBSUJOGPXMFSDPNCMJLJ$JSDVJU#SFBLFSIUNM

Slide 39

Slide 39 text

Inspired by … ?

Slide 40

Slide 40 text

Inspired by … ? •ΠϯεύΠΞ͞Εͨͱ͍͏ʹ͸࢓૊Έ͕͠ΐ΅͍ •τάϧͷ؅ཧʹ೉͕͋Δ •ϒϨʔΧʔΛམͱ͢৚͕݅ͨͩͷճ਺ •ࣗಈ෮ؼ͠ͳ͍ •DB ΞΫηεΛ͢ΔͷͰΦʔόʔϔου͕ੜ͡Δ

Slide 41

Slide 41 text

ɹো֐͕ଟ͍ΜͰ͢Α…😣 ɹ90% ϛε͕ͳ͍͜ͱͷอূ͸ͦͦ͜͜Ͱ͖Δ͚Ͳ 
 ɹ100% ϛε͕ͳ͍͜ͱͷอূ͸ͱͯ΋ߴίετ ɹϦϦʔεස౓Λ্͛Δͷ͕೉ͯ͘͠…😭 ɹ͙͢ʹ੾Γ໭ͤΔΑ͏ʹͨ͠ํ͕ 
 ɹ݈શ͔΋͠Ε·ͤΜͶ

Slide 42

Slide 42 text

Ұ఺ूத •΄͍͠ͷ͸ʮ௿ίετʹ੾Γ໭ͤΔʯ࢓૊Έ •ͱʹ͔͘ࠓ΄͍͠ ػೳ͚ͩΛ࣮૷ͯ͠ϦϦʔε

Slide 43

Slide 43 text

ॠൃྗ •ͱΓ͋͑ͣ΄͔ͬͨ͠ •ϨϏϡʔɾௐࠪɾςετίετ͕૿େ͍ͯ͠Δঢ়گΛվળ͍ͨ͠ •ݱ৔ͷࠓ͋Δ՝୊Λࠓ͙͢ղܾ͍ͨ͠ •଍Γͳ͍஌ࣝɾٕज़͸ͨ͘͞Μ͋Δ •४උ͕Ͱ͖Δ·Ͱ଴ͭͱ͋ͬͱ͍͏ؒʹ݄೔͕ա͗Δ

Slide 44

Slide 44 text

ॠൃྗ •MVP •Minimum Viable Product •࣮༻࠷খݶͷ੡඼ •ఏڙ͠ͳ͕Β։ൃ͢Δ

Slide 45

Slide 45 text

΍Βͳ͍ཧ༝ •ͦ͏͔΋͠Εͳ͍ •ͦ͏Ͱͳ͍͔΋͠Εͳ͍ •OSS ʹ͓͚ͯ͠͹୭͔ͷ໾ʹཱ͔ͭ΋͠Εͳ͍ •OSS ʹ͠ͳ͍ཧ༝͸ͳ͍ ɹgem ʹ͠ͳͯ͘΋͍͍Μ͡Όͳ͍ʁ

Slide 46

Slide 46 text

՝୊ʹΞϓϩʔν͢Δ •ίʔυͷ೉͠͞ͱϥΠϒϥϦͷՁ஋͸ؔ܎ͳ͍ ɹ͜Μͳ͠ΐ΅͍ίʔυΛੈʹग़͢ͳΜͯ…

Slide 47

Slide 47 text

·ͣ͸͍ͪ࢝͘͞ΊΔ

Slide 48

Slide 48 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠