Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
circuit_switch: small start to create gem
Search
makicamel
October 10, 2021
Programming
3
2.6k
circuit_switch: small start to create gem
at 2021.10.10. Kaigi on Rails _2021_ new
makicamel
October 10, 2021
Tweet
Share
More Decks by makicamel
See All by makicamel
ErdMap: Thinking about a map for Rails applications
makicamel
1
580
dRuby 入門者によるあなたの身近にあるdRuby 入門
makicamel
4
770
BulletmarkRepairer: auto corrector for N+1 queries
makicamel
10
6.8k
How to say goodbye to technical debt
makicamel
8
2.9k
Ganbaranai wo ganbaru
makicamel
5
4.4k
Automate the boring staff with Ruby
makicamel
1
960
Lets enjoy creating gems
makicamel
3
1.9k
Play with Rubys AST
makicamel
0
1.9k
Lets enjoy code reading
makicamel
5
910
Other Decks in Programming
See All in Programming
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
300
php-conference-japan-2024
tasuku43
0
430
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
390
Azure AI Foundryのご紹介
qt_luigi
1
160
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
140
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1.3k
HTML/CSS超絶浅い説明
yuki0329
0
190
Внедряем бюджетирование, или Как сделать хорошо?
lamodatech
0
930
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
8
1.9k
テストコード書いてみませんか?
onopon
2
330
Androidアプリのモジュール分割における:x:commonを考える
okuzawats
1
270
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
Featured
See All Featured
Practical Orchestrator
shlominoach
186
10k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Bash Introduction
62gerente
610
210k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
YesSQL, Process and Tooling at Scale
rocio
170
14k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
230
52k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
210
Optimising Largest Contentful Paint
csswizardry
33
3k
Being A Developer After 40
akosma
89
590k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
327
24k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
240
Transcript
DJSDVJU_TXJUDI ͍ͪ࢝͘͞ΊΔHFNͮ͘Γ 2021.10.10. Kaigi on Rails _2021_ new @makicamel
w!NBLJDBNFMݪສق w3VCZͱϏʔϧɹɹͱ͓ञ͕͖ w͖ͳ73ήʔϜ ࣗݾհ
࠷ۙࠔ͍ͬͯΔ͜ͱ ͓ࣄͰ
ো͕ଟ͍
•ӨڹൣғௐࠪΛ͕ΜΖ͏ •ϨϏϡʔΛ͕ΜΖ͏ •ࣗಈςετͷՃɾϝϯςΛ͕ΜΖ͏ •खಈςετΛ͕ΜΖ͏ •ΤϥʔࢹΛ͕ΜΖ͏ োΛىͨ͜͠ਓྨͷߟ͕͑ͪͳ͜ͱ ͬͱ ͬͱ ͬͱ ͬͱ
ͬͱ
͕ΜΓͨ͘ͳ͍
•͕ΜΔͱϛεΔ •͕ΜΓݸਓʹґଘ •͕ΜΔͱർΕΔ •͕ΜΔӬԕʹܧଓͰ͖ͳ͍ ͕ΜΓͨ͘ͳ͍
ΈͰͳΜͱ͔͍ͨ͠
ɹো͕ଟ͍ΜͰ͢Α…😣 ɹ90% ϛε͕ͳ͍͜ͱͷอূͦͦ͜͜Ͱ͖Δ͚Ͳ ɹ100% ϛε͕ͳ͍͜ͱͷอূͱͯߴίετ ɹϦϦʔεසΛ্͛Δͷ͕ͯ͘͠…😭 ɹ͙͢ʹΓͤΔΑ͏ʹͨ͠ํ͕ ɹ݈શ͔͠Ε·ͤΜͶ
•ϦϦʔεिʹ 1 ճ ˞ ˞োରԠΛআ͘
•ϦϦʔεिʹ 1 ճ •100ʙ200 Pull Requests •500ʙ1,000 commits •10Kʙ60K lines
˞ ϏοάόϯϦϦʔε ˞Ұ൪ݹ͘ػೳ͕ଟ͍ϞϊϦγοΫϦϙδτϦʹ͓͚Δɻଟ͘ͷଞϦϙδτϦͬͱԺ͔Ͱ͢ ˞োରԠΛআ͘ ˞
ϦϦʔείετ͕ߴͯ͘ো͕ଟ͘ɾେ͖͘ͳΓ͕ͪ ো͕ଟͯ͘ϦϦʔεසΛ্͛ΒΕͳ͍ ϏοάόϯϦϦʔε
ͱ͍͏Θ͚Ͱ
ͭͬͨ͘ NBLJDBNFMDJSDVJU@TXJUDI IUUQTHJUIVCDPNNBLJDBNFMDJSDVJU@TXJUI
circuit_switch
ɹো͕ଟ͍ΜͰ͢Α…😣 ɹ90% ϛε͕ͳ͍͜ͱͷอূͦͦ͜͜Ͱ͖Δ͚Ͳ ɹ100% ϛε͕ͳ͍͜ͱͷอূͱͯߴίετ ɹϦϦʔεසΛ্͛Δͷ͕ͯ͘͠…😭 ɹ͙͢ʹΓͤΔΑ͏ʹͨ͠ํ͕ ɹ݈શ͔͠Ε·ͤΜͶ
circuit_switch Γ͍ͨ͜ͱɿ ϦϦʔεසΛ͋͛Δ ˞ϦϦʔεස͍͋͛ͨͰ͢
circuit_switch Γ͍ͨ͜ͱɿ ίετʹΓ͢
circuit_switch if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end
CircuitSwitch.report(if: unexpected_happen)
circuit_switch if CircuitSwitch.open?(close_if_reach_limit: false) do_something_experimental else call_existing_codes end
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
circuit_switch •CircuitSwitch ͷ։ด݅ نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
circuit_switch •CircuitSwitch ͷ։ด݅ if CircuitSwitch.open?(reach_limit: 100) do_something_experimental else call_existing_codes
end نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
circuit_switch if CircuitSwitch.open?(if: current_user.testing?) do_something_experimental else call_existing_codes end •CircuitSwitch
ͷ։ด݅ نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
circuit_switch if CircuitSwitch.open?( close_if: Date.today > some_period ) do_something_experimental
else call_existing_codes end •CircuitSwitch ͷ։ด݅ نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
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 نఆ্ݶճʹ౸ୡ ։์݅ͱҰக ด݅ͱҰக ৗ࣮࣌ߦʴڧ੍ด
circuit_switch CircuitSwitch.report(if: unexpected_happen) •CircuitSwitch ͕։͍͍ͯΔ࣌ report ΛૹΔ •Slack
Bugsnag ͳͲҙͷϨϙʔτπʔϧΛࢦఆ •։ด݅ open? ͱྨࣅͷ݅Λࢦఆ
circuit_switch •ґଘϥΠϒϥϦ •ActiveRecord •࣮ߦߦʢcallerʣɾCircuitSwitch ͷ։ดঢ়ଶΛ DB ʹอଘ •ActiveJob •DB ߋ৽ɾϨϙʔτ
circuit_switch •ίʔυϦʔμʔͷΈͲ͜Ζ
circuit_switch •ίʔυϦʔμʔͷΈͲ͜Ζ •ͳ͍
circuit_switch •ίʔυϦʔμʔͷΈͲ͜Ζ •ͳ͍ •ͳ͍ͷ͕ΈͲ͜Ζʢʁʣ
ΈͲ͜Ζ •ԿมΘͬͨ͜ͱΛ͍ͬͯͳ͍ •Rails ͷίʔυ͕ॻ͚ͨΒॻ͚Δ •ࠓ͙͢ॻ͖࢝ΊΒΕΔ
ΈͲ͜Ζ •;ͭ͏ͷ Rails ΞϓϦ͕ґଘ͍ͯ͠ΔϥΠϒϥϦʹґଘ •ࠓ͙͢ಋೖͰ͖Δ
ͱ͜ΖͰ͓ؾ͖͔ͮͱࢥ͍·͕͢
Inspired by •Feature Toggles •CircuitBreaker 'FBUVSF5PHHMFTNBSUJOGPXMFSDPN IUUQTNBSUJOGPXMFSDPNBSUJDMFTGFBUVSFUPHHMFTIUNM $JSDVJU#SFBLFSNBSUJOGPXMFSDPN
IUUQTNBSUJOGPXMFSDPNCMJLJ$JSDVJU#SFBLFSIUNM
Feature Toggles •৽ػೳΛಛఆϢʔβʹ҆શɾ͔ʹఏڙ͢ΔͨΊͷΈ •ؔ࿈ɿDark Launch •🙅 େن feature ϒϥϯν্Ͱͷ։ൃ
🙆 master(main) ϒϥϯνʹ߹ྲྀͨ͠։ൃ 'FBUVSF5PHHMFTNBSUJOGPXMFSDPN IUUQTNBSUJOGPXMFSDPNBSUJDMFTGFBUVSFUPHHMFTIUNM
Feature Toggles •ΧφϦΞϦϦʔε •ϥϯμϜબग़ͷۃҰ෦ͷҰൠϢʔβʹػೳ։์༷ͯ͠ࢠݟ •A / B ςετ 'FBUVSF5PHHMFTNBSUJOGPXMFSDPN
IUUQTNBSUJOGPXMFSDPNBSUJDMFTGFBUVSFUPHHMFTIUNM
CircuitBreaker •αʔόʹಛఆճҎ্ͷো͕ൃੜͨ࣌͠ʹ ϦΫΤετΛड͚͚ͣʹΤϥʔΛฦ͢Έ •োͷ࿈తͳൃੜΛ͙ •αʔό͕վળͨ͠ΒࣗಈͰ෮ؼ͢Δ $JSDVJU#SFBLFSNBSUJOGPXMFSDPN IUUQTNBSUJOGPXMFSDPNCMJLJ$JSDVJU#SFBLFSIUNM
Inspired by … ?
Inspired by … ? •ΠϯεύΠΞ͞Εͨͱ͍͏ʹΈ͕͠ΐ΅͍ •τάϧͷཧʹ͕͋Δ •ϒϨʔΧʔΛམͱ͕݅ͨͩ͢ͷճ •ࣗಈ෮ؼ͠ͳ͍ •DB ΞΫηεΛ͢ΔͷͰΦʔόʔϔου͕ੜ͡Δ
ɹো͕ଟ͍ΜͰ͢Α…😣 ɹ90% ϛε͕ͳ͍͜ͱͷอূͦͦ͜͜Ͱ͖Δ͚Ͳ ɹ100% ϛε͕ͳ͍͜ͱͷอূͱͯߴίετ ɹϦϦʔεසΛ্͛Δͷ͕ͯ͘͠…😭 ɹ͙͢ʹΓͤΔΑ͏ʹͨ͠ํ͕ ɹ݈શ͔͠Ε·ͤΜͶ
Ұूத •΄͍͠ͷʮίετʹΓͤΔʯΈ •ͱʹ͔͘ࠓ΄͍͠ ػೳ͚ͩΛ࣮ͯ͠ϦϦʔε
ॠൃྗ •ͱΓ͋͑ͣ΄͔ͬͨ͠ •ϨϏϡʔɾௐࠪɾςετίετ͕૿େ͍ͯ͠Δঢ়گΛվળ͍ͨ͠ •ݱͷࠓ͋Δ՝Λࠓ͙͢ղܾ͍ͨ͠ •Γͳ͍ࣝɾٕज़ͨ͘͞Μ͋Δ •४උ͕Ͱ͖Δ·Ͱͭͱ͋ͬͱ͍͏ؒʹ݄͕ա͗Δ
ॠൃྗ •MVP •Minimum Viable Product •࣮༻࠷খݶͷ •ఏڙ͠ͳ͕Β։ൃ͢Δ
Βͳ͍ཧ༝ •ͦ͏͔͠Εͳ͍ •ͦ͏Ͱͳ͍͔͠Εͳ͍ •OSS ʹ͓͚ͯ͠୭͔ͷʹཱ͔ͭ͠Εͳ͍ •OSS ʹ͠ͳ͍ཧ༝ͳ͍ ɹgem ʹ͠ͳ͍͍ͯ͘Μ͡Όͳ͍ʁ
՝ʹΞϓϩʔν͢Δ •ίʔυͷ͠͞ͱϥΠϒϥϦͷՁؔͳ͍ ɹ͜Μͳ͠ΐ΅͍ίʔυΛੈʹग़͢ͳΜͯ…
·͍ͣͪ࢝͘͞ΊΔ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠