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
Firestoreコスト圧縮の旅
Search
Daiki Hirakata
May 21, 2024
Technology
0
28
Firestoreコスト圧縮の旅
Daiki Hirakata
May 21, 2024
Tweet
Share
More Decks by Daiki Hirakata
See All by Daiki Hirakata
Rails on Docker
bigplants
2
520
Road to k8s
bigplants
0
240
Next Level Git
bigplants
0
600
AWSを使っているならOpsWorksでDevOpsしよう!
bigplants
1
1.6k
Other Decks in Technology
See All in Technology
Product Engineer Night #6プロダクトエンジニアを育む仕組み・施策
hacomono
PRO
1
460
失敗しないOpenJDKの非互換調査
tabatad
0
270
visionOSでの空間表現実装とImmersive Video表示について / ai-immersive-visionos
cyberagentdevelopers
PRO
1
100
バクラクにおける可観測性向上の取り組み
yuu26
3
400
Autify Company Deck
autifyhq
1
39k
ガバメントクラウド先行事業中間報告を読み解く
sugiim
1
1k
IaC運用を楽にするためにCDK Pipelinesを導入したけど、思い通りにいかなかった話
smt7174
1
110
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
610
omakaseしないための.rubocop.yml のつくりかた / How to Build Your .rubocop.yml to Avoid Omakase #kaigionrails
linkers_tech
3
710
小規模に始めるデータメッシュとデータガバナンスの実践
kimujun
3
560
新卒1年目が挑む!生成AI × マルチエージェントで実現する次世代オンボーディング / operation-ai-onboarding
cyberagentdevelopers
PRO
1
160
Nix入門パラダイム編
asa1984
2
200
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
1
39
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Docker and Python
trallard
40
3.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
504
140k
A designer walks into a library…
pauljervisheath
202
24k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.1k
It's Worth the Effort
3n
183
27k
Done Done
chrislema
181
16k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Facilitating Awesome Meetings
lara
49
6k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Transcript
Firestore ίετѹॖͷཱྀ @bigplants May 21st 2024 @Hack@DELTA
Who am I ? • Daiki Hirakata (42) • Software
Engineer • Main Programing Languages: PHP, TypeScript • Primary interests: DevOps, Docker, Kubernetes, GCP @bigplants
ےϥϯφʔܥΤϯδχΞ
ͪΐͬͱ͚ͩએ
ઈࢍ։ൃऀืूதʂ • ϓϩμΫτ໊: ͨLuck • ళฮαʔϏεۀ͚ʹγϑτػೳ Λ͡Ίͱͨ͠DXαʔϏε • ϞόΠϧΞϓϦͱཧը໘ͷWebΛఏڙ •
PHP, TypeScript, Firebase, GCP • Laravel, React, Vue.js • גࣜձࣾHataLuck and Person
ͨLuckͷγεςϜߏ • DBFirestoreͱCloud SQL ͷϋΠϒϦουߏ • Firebase -> Cloud SQLʹҰ
෦ͷσʔλΛಉظ • APIFunctions, Cloud Run
ࠓͷ͓ • Firebaseͷར༻࣮ • FirestoreͷίετѹॖͷͨΊͷௐࠪ • ՝ۚѹॖͷͨΊʹͬͨ͜ͱ • ݱࡏ࣮ࢪதͷࢪࡦͱ͜Ε͔Β
Firebaseͷར༻࣮
نײ • Cloud Functions • HTTP Trigger: 184 • Event
Trigger: 167 • Cloud Firestore • Collections: over 100
Firestoreίετ • GCPશମͷ5ׂ͕Firestore • 98%Read! Read 3.5ԯ/day
Firestoreίετ 20221݄͔Βݱࡏ·Ͱ ૿͑ͯݮΒͯ͠ɺ·ͨ૿͑ͯ
Ͳ͔͜ΒRead͞Ε͍ͯΔͷ͔ʁ • Cloud Functions • iOS/Android • ཧը໘ͷWeb
FirestoreίετѹॖͷͨΊͷ ௐࠪ
ԿΛௐࠪ͢Δ͔ʁ • ௐࠪͷతͲͷػೳ͔Β࠷Read͕ଟ͍͔ ಛఆͯ͠ରԠ͢Δػೳͷ༏ઌΛ͚ͭΔ͜ͱ • අ༻ରޮՌ͕ߴ͍ͱ͜Ζ͔Βணख͍ͯ͘͠ • ػೳผɺΞΫηεݩΫϥΠΞϯτผʹReadͷ ݅Λूܭ͢Δ
Ͳ͔͜Β݅Λநग़Ͱ͖Δͷ ͔ʁ • ࠪϩά • Firestore/Datastore API • ※ ͜Ε͕།ҰͷFirestoreͷΞΫηεϩά
ࠪϩάͷඅ༻: ¥18,000/day!
ࠪϩάͰऔΕΔσʔλ • ΦϖϨʔγϣϯ • GetDocument, RunQuery, CreateDocument ͳͲͳͲ • υΩϡϝϯτͷύε
• ϢʔβΤʔδΣϯτ
ࠪϩά • ٻϨϙʔτͷRead OpsͱࠪϩάΛ͚߹ ΘͤΔ • ٻϨϙʔτͷSKU: Cloud Firestore Read
Ops Japanͷ͕݅՝ۚ୯Ґ
ۤ࿑ͨ͠ͱ͜Ζᶃ • FirestoreͷΞΫηεݩΛಛఆ͖͠Εͳ͍ • FunctionsͰFirestore TriggerΠϕϯτͳͷ͔ HTTP TriggerΠϕϯτͳͷ͔Θ͔Βͳ͍ • ListenͰ࣮ࡍʹRead՝͕ۚΔରͷϩά͕ͲΕ͔
ผΛ͚ͭΒΕͳ͍
ۤ࿑ͨ͠ͱ͜Ζᶄ • ࠪϩάͱRead Opsͷ͕݅શવ߹Θͳ͍ • ࠷ऴతͳGoogleαϙʔτ͔Βͷճ • ʮࠪϩά͔ΒRead Opsͷ༁͑ͳ͍ Αʙʯ
<- Ͱ͖Δͬͯݴͬͨ͡ΌʔΜ orz
ௐࠪஅ೦ʂʂ (1.5ϲ݄Λඅͨ͠)
ͦΕͰಈ͖ग़͞ͳ͚Εʂ
՝ۚѹॖͷͨΊʹͬͨ͜ͱ
՝ۚѹॖࢪࡦ • FirestoreτϦΨFunctionsͷೋॏൃՐࢭͷϦ ΞʔΩςΫνϟ • ΞΫςΟϏςΟϩάͷҠߦ • FirestoreΩϟογϡػߏͷߏங • ΤΫεϙʔτରσʔλΛਫ਼ࠪ
FirestoreτϦΨFunctions ͷೋॏൃՐʁ • FirestoreτϦΨFunctionsॏෳ࣮ͯ͠ߦ͞Ε Δ͜ͱ͕͋Δ • ႈੑ͕୲อ͞Ε͍ͯΕOK͕ͩɺɺ
ႈੑ͕୲อ͞Ε͍ͯͳ͍ Functions͕ଟ͋Γ
Functions͕ೋॏʹൃՐ͠ͳ͍ Έ͕ඞཁ
ͱͱ࣮ࢪ͍ͯͨ͠ೋॏൃՐ ࢭͷΈ • ൃՐ࣌ʹΠϯϕϯτIDΛFirestoreʹॻ͖ࠐΉ • ΠϕϯτID͕͢Ͱʹଘࡏ͢ΕॲཧΛεΩο ϓɻͳ͚ΕॲཧΛߦ͏
ΠϕϯτIDΛFirestoreʹ֨ೲ
Firestoreॻ͖ࠐΈίετ͕૿Ճ • ࠷ॳؾʹͳΒͳ͍͘Β͍͕ͩͬͨػೳ͕૿ ͑ɺϦΫΤετ͕૿͑ͯ͘ΔͱͦΕͳΓʹ ཱͭΑ͏ʹͳͬͨ
ೋॏൃՐࢭͷϦΞʔΩςΫ νϟ • ॻ͖ࠐΈઌΛFirestore ͔Β Redis ʹมߋ • شൃσʔλFirestoreʹஔ͔ͳ͍ 💰
¥50,000/month ѹॖ (Write)
ΞΫςΟϏςΟϩάͷҠߦ • ΞΫςΟϏςΟϩάͱಛఆͷϢʔβૢ࡞ͷϩά ͷ͜ͱ • ͱͱFirestoreʹϩάΛ֨ೲ͍ͯͨ͠ • Ϣʔβ͕૿͑Δͱ͡Θ͡Θॻ͖ࠐΈྔ͕ଟ͘ͳΔ • FirestoreͷΤΫεϙʔτରσʔλʹͳ͍ͬͯͨ
ΞΫςΟϏςΟϩάͷҠߦ • Firestore ͔Β BigQuery ʹҠߦ • ΤΫεϙʔτର͔Βআ֎ • ϩάFirestoreʹஔ͔ͳ͍ʂ
💰 ¥50,000/month ѹॖ (Write) 💰 ¥500,000/month ѹॖ (ΤΫεϙʔτͷRead)
FirestoreΩϟογϡػߏͷߏங • ϢʔβϚελళฮϚελͳͲΑ͘ࢀর͞Ε ΔσʔλΛRedisʹΩϟογϡ 💰 ¥100,000/month ѹॖ (Read)
ͦΕͰͳ͓૿͑ଓ͚Δίετ
ݱࡏਐߦதͷίετѹॖରࡦ With גࣜձࣾDELTA͞Μ
FirestoreͷΤΫεϙʔτΛΊ Δ • ۙ ¥100Ϛϯ/݄ͷReadͷ͕ΤΫεϙʔ τ • ΤΫεϙʔτͷత • όοΫΞοϓ(༗ࣄͷࡍͷ෮ݩ͕త)
• σʔλੳ༻్ͷBigQueryΠϯϙʔτ
FirestoreͷόοΫΞοϓ • FirestoreͷόοΫΞοϓ εέδϡʔϧͱϙΠ ϯτΠϯλΠϜϦΧόϦʹஔ͖͑
σʔλੳ • ࠩόοΫΞοϓΛBigQuery • Firebase ExtensionsΛར༻
Stream Firestore to BigQuery • https://extensions.dev/extensions/ fi rebase/ fi restore-bigquery-export
• Cloud Firestore ίϨΫγϣϯͷυΩϡϝϯτ Λ BigQuery ʹΤΫεϙʔτɻΤΫεϙʔτϦ ΞϧλΠϜ͔ͭ૿Ͱ͋ΔͨΊɺBigQuery ͷσʔ λ Cloud Firestore ͷίϯςϯπͷϛϥʔͱ Δɻ
FirestoreશҠߦ
͍ͭʹຊ֨࢝ಈʂʂ
Firestore -> Cloud SQLͷҠ ߦ Cloud Functions Cloud Firestore Cloud
Run Cloud SQL ̍Ҏ্ͷϓϩδΣΫτʹͳΔ
Firestoreʹ͍ͭͯ͏ࣄ • εέʔϥϏϦςΟ͕ߴͯ҆͘ՁͳͷͰɺαʔϏε্ཱͪ ͛࣌ΧδϡΞϧʹԿͰஔ͖ͨ͘ͳΔ • ͕ɺɺ͋ͱ͋ͱɺ͓ۚʹΨπϯͱͶฦͬͯ͘Δ • αʔϏεن͕େ͖͘ͳΔͱσʔλετΞFirestoreͩ ͚ͰԿ͔ͱਏ͍ •
͍ॴҰ෦ͷϚΠΫϩαʔϏεͷόοΫΤϯυͱଊ͑ ͓ͯ͘ͱͬ͘͠Γ͘Δ
ࠓͷ·ͱΊ • ϩάشൃσʔλFirestoreʹͳΔ͘ஔ ͔ͳ͍ • Ϣʔβ͕૿͑Δͱ৭Μͳͷ͕δϫδϫͱ ૿͍͑ͯ͘ • Firestoreن͕େ͖͘ͳͬͯ͘Δͱίετί ϯτϩʔϧ͕͘͠ͳΔ
Thank You 🛹 ཱྀͭͮ͘