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
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
Go の GC の不得意な部分を克服したい
taiyow
2
770
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
5
900
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
700
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
700
Featured
See All Featured
It's Worth the Effort
3n
183
28k
Mobile First: as difficult as doing things right
swwweet
222
9k
Into the Great Unknown - MozCon
thekraken
33
1.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Thoughts on Productivity
jonyablonski
67
4.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Producing Creativity
orderedlist
PRO
341
39k
Statistics for Hackers
jakevdp
796
220k
The Cost Of JavaScript in 2023
addyosmani
45
7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
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 ʹ͠ͳ͍͍ͯ͘Μ͡Όͳ͍ʁ
՝ʹΞϓϩʔν͢Δ •ίʔυͷ͠͞ͱϥΠϒϥϦͷՁؔͳ͍ ɹ͜Μͳ͠ΐ΅͍ίʔυΛੈʹग़͢ͳΜͯ…
·͍ͣͪ࢝͘͞ΊΔ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠