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.5k
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
dRuby 入門者によるあなたの身近にあるdRuby 入門
makicamel
4
720
BulletmarkRepairer: auto corrector for N+1 queries
makicamel
10
6.7k
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
950
Lets enjoy creating gems
makicamel
3
1.9k
Play with Rubys AST
makicamel
0
1.8k
Lets enjoy code reading
makicamel
5
900
OSS is great but not special
makicamel
7
7.7k
Other Decks in Programming
See All in Programming
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
270
情報漏洩させないための設計
kubotak
1
130
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
たのしいparse.y
ydah
3
120
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
470
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
930
Refactor your code - refactor yourself
xosofox
1
260
快速入門可觀測性
blueswen
0
350
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
We Have a Design System, Now What?
morganepeng
51
7.3k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Git: the NoSQL Database
bkeepers
PRO
427
64k
A Philosophy of Restraint
colly
203
16k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Being A Developer After 40
akosma
87
590k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Rails Girls Zürich Keynote
gr2m
94
13k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
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 ʹ͠ͳ͍͍ͯ͘Μ͡Όͳ͍ʁ
՝ʹΞϓϩʔν͢Δ •ίʔυͷ͠͞ͱϥΠϒϥϦͷՁؔͳ͍ ɹ͜Μͳ͠ΐ΅͍ίʔυΛੈʹग़͢ͳΜͯ…
·͍ͣͪ࢝͘͞ΊΔ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠