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
29
Firestoreコスト圧縮の旅
Daiki Hirakata
May 21, 2024
Tweet
Share
More Decks by Daiki Hirakata
See All by Daiki Hirakata
Rails on Docker
bigplants
2
530
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
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
スクラム成熟度セルフチェックツールを作って得た学びとその活用法
coincheck_recruit
1
140
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
110
ISUCONに強くなるかもしれない日々の過ごしかた/Findy ISUCON 2024-11-14
fujiwara3
8
870
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
130
iOS/Androidで同じUI体験をネ イティブで作成する際に気をつ けたい落とし穴
fumiyasac0921
1
110
AIチャットボット開発への生成AI活用
ryomrt
0
170
いざ、BSC討伐の旅
nikinusu
2
780
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
スクラムチームを立ち上げる〜チーム開発で得られたもの・得られなかったもの〜
ohnoeight
2
350
Application Development WG Intro at AppDeveloperCon
salaboy
0
180
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
470
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Statistics for Hackers
jakevdp
796
220k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Six Lessons from altMBA
skipperchong
27
3.5k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.2k
Building an army of robots
kneath
302
43k
Bash Introduction
62gerente
608
210k
For a Future-Friendly Web
brad_frost
175
9.4k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Documentation Writing (for coders)
carmenintech
65
4.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
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 🛹 ཱྀͭͮ͘