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
35
Firestoreコスト圧縮の旅
Daiki Hirakata
May 21, 2024
Tweet
Share
More Decks by Daiki Hirakata
See All by Daiki Hirakata
Rails on Docker
bigplants
2
540
Road to k8s
bigplants
0
250
Next Level Git
bigplants
0
610
AWSを使っているならOpsWorksでDevOpsしよう!
bigplants
1
1.6k
Other Decks in Technology
See All in Technology
KMP with Crashlytics
sansantech
PRO
0
140
普通のエンジニアがLaravelコアチームメンバーになるまで
avosalmon
0
690
ネットワーク可視化の世界
likr
7
5.7k
Oracle Base Database Service:サービス概要のご紹介
oracle4engineer
PRO
1
16k
20240513 - 框裡框外_文學院學生如何在AI世代安身立命 @ 淡江大學
dpys
0
640
20240522 - 躍遷創作理念 @ PicCollage Workshop
dpys
0
310
.NET AspireでAzure Functionsやクラウドリソースを統合する
tsubakimoto_s
0
150
Cloudflareで実現する AIエージェント ワークフロー基盤
kmd09
0
240
Unlearn Product Development - Unleashed Edition
lemiorhan
PRO
2
170
AWS re:Invent 2024 ふりかえり勉強会
yhana
0
710
The future we create with our own MVV
matsukurou
0
1.8k
OCI技術資料 : ファイル・ストレージ 概要
ocise
3
12k
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
7
560
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
860
jQuery: Nuts, Bolts and Bling
dougneiner
62
7.6k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Docker and Python
trallard
43
3.2k
A better future with KSS
kneath
238
17k
Adopting Sorbet at Scale
ufuk
74
9.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 🛹 ཱྀͭͮ͘