SlideShare a Scribd company logo
Optimizing Cloud Firestore
Reads
By: Ryan Sneyd
Quick Definitions
Firebase: The name of the suite of tools Google uses to provide BaaS (Backend as a Service)
Real Time Database: Document based NoSQL used for smaller projects that require low latency
Cloud FireStore: The new version of Real Time Database that is faster and more scalable
Document: Holds data that contains a key that can be indexed and value associated with that key (Think
table of contents that has a name of a chapter (Key) and a page number (Value))
Collection: List of documents
Pricing Models
Google charges users a fixed fee for every read, write and delete operation
Google also charges for the amount of GB stored on their network
Google offers three plans:
- Spark: Free tier with limited daily usage
- Flame: $25/month plan that stops charging if users go over a specific limit
- Blaze: Pay-as-you-go plan that charges based on usage (See next slide)
See https://firebase.google.com/pricing for more details
Blaze Pricing Model Breakdown
*price in USD
[1]"Understand Cloud Firestore billing | Firebase", Firebase, 2019. [Online]. Available:
https://firebase.google.com/docs/firestore/pricing. [Accessed: 15- Jul- 2019].
Managing Reads and Writes
Google sets the Blaze plan as default but it can be switched to any plan based on the users needs
Since Google charges based on Read, Write and Delete operations there are strategies that can be used
to minimize reads and writes and subsequently optimize your backend
The goal is to give Google as little money as possible and avoid spending “$30,356.56 USD in just 72
hours” [8]
[8]N. Contreras, "How we spent 30k USD in Firebase in less than 72 hours - By", Hackernoon.com, 2019. [Online]. Available:
https://hackernoon.com/how-we-spent-30k-usd-in-firebase-in-less-than-72-hours-307490bd24d. [Accessed: 22- Jul- 2019].
How Reads and Writes works
Reads
- When data is received from a document using get() or exist()
- If data in a document is changed and client reads the update
- If user logs out and logs back in after 30 minutes and reads the same data
Writes
- set() and update() are called
- Everytime the data is manually changed in Cloud Firestore
Deletes
- Anytime a document is deleted or document field is deleted
[1]"Understand Cloud Firestore billing | Firebase", Firebase, 2019. [Online]. Available:
https://firebase.google.com/docs/firestore/pricing. [Accessed: 15- Jul- 2019].
Strategies for Optimizing Reads and Writes
Strategy 1:
- Minimize hotspotting on Firestore
Strategy 2:
- Use Transactions and Batch Writes along with other Google recommended practices
Strategy 3:
- Follow Document Based NoSQL design patterns when modeling data
Hotspotting
Hotspotting: When one part of a system is being overloaded instead of being distributed across the
whole system
This occurs when:
- Many documents are being created at once with incrementing/decrementing ids
- Generating lots of documents in small collections
- Adding data that frequently changes (i.e timestamps)
- Deleting multiple documents in a collection
- Writing to a document too frequently without gradually increasing traffic
[2]"Best practices | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/best-practices#hotspots. [Accessed: 15- Jul- 2019].
Minimizing hotspotting
Document Ids
- Avoid using the characters . .. and /
- Do not use incrementing ids (i.e. Customer1, Customer2, Customer3 …)
- Best to use a unique identifier such as a Username or email
Field names
- Avoid using periods, brackets, asterisk and backticks (Requires extra processing)
Indexing
- Avoid indexing as it increases storage costs
- Only use indexing to partition or retreive expensive data (i.e large text file, large arrays)
[2]"Best practices | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/best-practices#hotspots. [Accessed: 15- Jul- 2019].
Following Google’s Best Practices
Avoid writing more that one document per second
- This can lead to high latency, timeouts or worse
Use Asynchronous calls over synchronous calls
Use cursors instead of offsets
Use transactions and batch writes for reads and writes
[2]"Best practices | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/best-practices#hotspots. [Accessed: 15- Jul- 2019].
Transactions and Batch Writes
Transactions and batch writes are used to perform atomic operations meaning it “guaranteed to be
isolated from other operations that may be happening at the same time.” [3]
Transaction is a set of reads and writes operations on one or more documents. [4]
Batch write is a set of write operations on one or more documents. [4]
[3]J. Fisher, "What the Heck Is an "Atomic Object"?", Atomic Spin, 2019. [Online]. Available:
https://spin.atomicobject.com/2016/01/06/defining-atomic-object/. [Accessed: 15- Jul- 2019].
[4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
Transactions
A transaction is any get() operation followed by any set(), update() or delete() operation
By using transactions data is guaranteed to be up to date and consistent
Things to note:
- Read operations must come before write operations
- Transaction may be executed more than once if there are concurrent edits
- Transaction should not directly modify the application state
- Transactions will fail if the client is offline
[4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
Transaction in Python
[4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
Transaction Failure
A transaction will fail if:
- Transaction contains read operations after a write operation
- A document was modified during a transaction. In this case the transaction will retry for a set
number of times
- Transaction size is greater than 10 MB
Failed transactions does not write to firestore
[4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
Batch Write
Batch writes allow you to write a combination set(), update() or delete() operations as a single atomic
action.
Batch write can hold up to 500 operations
Other operations include serverTimestamp() , arrayUnion() and increment()
Batch writes are less likely to fail and will not retry like transactions will
Batch writes will execute even if the client is offline
[4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
Batch Write in Python
[4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
Designing Document Based NoSQL
In traditional database tables have schema, a set on constraints the data must follow
In Firestore, data is schema-less meaning it does not have to follow constraints
[5]Microsoft, LocalDB used in Microsoft Visual Studio. 2019.
[6]Medium, Document used in Firebase Firestore. 2019.
Polymorphic Schema
Because there are no constraints to follow we can put any type of data into a collection which makes the
schema polymorphic or can take “many forms” [7]
An example could be an online store that sells Appliances, CDs and Books
Each item has similar attributes like price, name and quantity but also unique ones like:
- Books have a Page Number
- CDs have a Song Count
- Appliances have a type such as Kitchen
[7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
Polymorphic Schema
Since our online store will always be displaying the price, name and quantity to our users, the three
products will be retrieved the same way
Instead of a storing each product into separate collections for Books, CDs and Appliances it is better to
have a products collection because the data is retrieved the same
By simplifying our collections using a process known as denormalization, we reduce the number of reads
and writes to our database
Warning: Don’t over-simplify collections as it may reduce performance
[7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
One To Many Relationships
One to Many: When an instance of an entity has one or more related instances of another entity [7]
Examples include:
- A Garage contains one or many cars
- A shelf contains one or many books
Suggested Practice: To put the multiple instances as a map or array inside the single instance [7]
[7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
One To Many Example
Location Instance 1
Location Instance 2
Single
Instance
Customer
[7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
Many to Many Relationships
Many to Many: When multiple instances of one entity are related to multiple instances of another entity
[7]
Examples Include:
- Many students take many classes
- Many doctors have many patients
Suggested Practice: Use separate collections to represent the class of entities. Documents in the
collection contain references to the data they are related to. [7]
[7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
Many to Many Example
Courses Collection
Students Collection
Reference To Student Document
Course Document
Student Document Reference To Courses Document
[7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
Hierarchy Relationships
Hierarchy: Instances of entities in some kind of parent-child or part-subpart relationship [7]
Examples:
- Creating a recliner, table and desk as parts of a furniture collection
- Creating a lion, tiger and bobcat as children of a cat collection
Suggested Practice: Give child entities a reference to the parent entities [7]
[7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
Hierarchy Example
Parent Reference
[7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
Conclusion
In my experience, following these guidelines will help:
- Organize your data
- Make faster queries
- Create repeatable quality
- Reduce costs
Overall not just improving your user’s experience but your wallet’s experience as well
References
[1]"Understand Cloud Firestore billing | Firebase", Firebase, 2019. [Online]. Available:
https://firebase.google.com/docs/firestore/pricing. [Accessed: 15- Jul- 2019].
[2]"Best practices | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available:
https://cloud.google.com/firestore/docs/best-practices#hotspots. [Accessed: 15- Jul- 2019].
[3]J. Fisher, "What the Heck Is an "Atomic Object"?", Atomic Spin, 2019. [Online]. Available:
https://spin.atomicobject.com/2016/01/06/defining-atomic-object/. [Accessed: 15- Jul- 2019].
[4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online].
Available: https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes.
[Accessed: 15- Jul- 2019].
References
[5]Microsoft, LocalDB used in Microsoft Visual Studio. 2019.
[6]Medium, Document used in Firebase Firestore. 2019.
[7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
[8]N. Contreras, "How we spent 30k USD in Firebase in less than 72 hours - By", Hackernoon.com, 2019.
[Online]. Available: https://hackernoon.com/how-we-spent-30k-usd-in-firebase-in-less-than-72-
hours-307490bd24d. [Accessed: 22- Jul- 2019].

More Related Content

What's hot

Developing SAP Integration services in IBM BPM Advanced
Developing SAP Integration services in IBM BPM Advanced Developing SAP Integration services in IBM BPM Advanced
Developing SAP Integration services in IBM BPM Advanced
Logan Vadivelu
 
35 power bi presentations
35 power bi presentations35 power bi presentations
35 power bi presentations
Sean Brady
 
Mongo db intro.pptx
Mongo db intro.pptxMongo db intro.pptx
Mongo db intro.pptx
JWORKS powered by Ordina
 
Online Store Website Design Proposal PowerPoint Presentation Slides
Online Store Website Design Proposal PowerPoint Presentation SlidesOnline Store Website Design Proposal PowerPoint Presentation Slides
Online Store Website Design Proposal PowerPoint Presentation Slides
SlideTeam
 
Dynamodb Presentation
Dynamodb PresentationDynamodb Presentation
Dynamodb Presentation
advaitdeo
 
Online shopping system (E-commerce)
Online shopping system (E-commerce)Online shopping system (E-commerce)
Online shopping system (E-commerce)
Sarp Infotech
 
Web based online shopping system Presentation slide
Web based online shopping system Presentation  slideWeb based online shopping system Presentation  slide
Web based online shopping system Presentation slide
Rakibul Hasan Pranto
 
An Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDBAn Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDB
MongoDB
 
MongoDB Atlas
MongoDB AtlasMongoDB Atlas
MongoDB Atlas
MongoDB
 
Document Database
Document DatabaseDocument Database
Document Database
Heman Hosainpana
 
SRV405 Deep Dive Amazon Redshift & Redshift Spectrum at Cardinal Health
SRV405 Deep Dive Amazon Redshift & Redshift Spectrum at Cardinal HealthSRV405 Deep Dive Amazon Redshift & Redshift Spectrum at Cardinal Health
SRV405 Deep Dive Amazon Redshift & Redshift Spectrum at Cardinal Health
Amazon Web Services
 
MongoDB and Azure Databricks
MongoDB and Azure DatabricksMongoDB and Azure Databricks
MongoDB and Azure Databricks
MongoDB
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
Norberto Leite
 
Google BigQuery - Features & Benefits
Google BigQuery - Features & BenefitsGoogle BigQuery - Features & Benefits
Google BigQuery - Features & Benefits
Andreas Raible
 
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
Amazon Web Services Korea
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
César Trigo
 
Real-time Data Processing Using AWS Lambda
Real-time Data Processing Using AWS LambdaReal-time Data Processing Using AWS Lambda
Real-time Data Processing Using AWS Lambda
Amazon Web Services
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational Databases
Chris Baglieri
 

What's hot (20)

MongoDB
MongoDBMongoDB
MongoDB
 
Developing SAP Integration services in IBM BPM Advanced
Developing SAP Integration services in IBM BPM Advanced Developing SAP Integration services in IBM BPM Advanced
Developing SAP Integration services in IBM BPM Advanced
 
35 power bi presentations
35 power bi presentations35 power bi presentations
35 power bi presentations
 
Mongo db intro.pptx
Mongo db intro.pptxMongo db intro.pptx
Mongo db intro.pptx
 
Online Store Website Design Proposal PowerPoint Presentation Slides
Online Store Website Design Proposal PowerPoint Presentation SlidesOnline Store Website Design Proposal PowerPoint Presentation Slides
Online Store Website Design Proposal PowerPoint Presentation Slides
 
Dynamodb Presentation
Dynamodb PresentationDynamodb Presentation
Dynamodb Presentation
 
Online shopping system (E-commerce)
Online shopping system (E-commerce)Online shopping system (E-commerce)
Online shopping system (E-commerce)
 
Web based online shopping system Presentation slide
Web based online shopping system Presentation  slideWeb based online shopping system Presentation  slide
Web based online shopping system Presentation slide
 
An Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDBAn Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDB
 
MongoDB Atlas
MongoDB AtlasMongoDB Atlas
MongoDB Atlas
 
Document Database
Document DatabaseDocument Database
Document Database
 
Website designing proposal with price
Website designing proposal with priceWebsite designing proposal with price
Website designing proposal with price
 
SRV405 Deep Dive Amazon Redshift & Redshift Spectrum at Cardinal Health
SRV405 Deep Dive Amazon Redshift & Redshift Spectrum at Cardinal HealthSRV405 Deep Dive Amazon Redshift & Redshift Spectrum at Cardinal Health
SRV405 Deep Dive Amazon Redshift & Redshift Spectrum at Cardinal Health
 
MongoDB and Azure Databricks
MongoDB and Azure DatabricksMongoDB and Azure Databricks
MongoDB and Azure Databricks
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
 
Google BigQuery - Features & Benefits
Google BigQuery - Features & BenefitsGoogle BigQuery - Features & Benefits
Google BigQuery - Features & Benefits
 
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
Amazon EMR 고급 활용 기법 - AWS Summit Seoul 2017
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
Real-time Data Processing Using AWS Lambda
Real-time Data Processing Using AWS LambdaReal-time Data Processing Using AWS Lambda
Real-time Data Processing Using AWS Lambda
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational Databases
 

Similar to Optimizing cloud firestore reads

GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
AnkitRPradhan
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
SURYAPARIDA5
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
Surya66958
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
NikkhilK1
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
NikkhilK1
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
BinithKumar
 
Dannotes 50 - Collaboration Administration
Dannotes 50 - Collaboration AdministrationDannotes 50 - Collaboration Administration
Dannotes 50 - Collaboration Administration
Maurice Teeuwe
 
Getting Started With Multi-Cloud Architecture by PM Integrated
Getting Started With Multi-Cloud Architecture by PM IntegratedGetting Started With Multi-Cloud Architecture by PM Integrated
Getting Started With Multi-Cloud Architecture by PM Integrated
Organization
 
Google Cloud Dataproc - Easier, faster, more cost-effective Spark and Hadoop
Google Cloud Dataproc - Easier, faster, more cost-effective Spark and HadoopGoogle Cloud Dataproc - Easier, faster, more cost-effective Spark and Hadoop
Google Cloud Dataproc - Easier, faster, more cost-effective Spark and Hadoop
huguk
 
DATA COMMUNICATION & COMPUTER NETWORK.pptx
DATA COMMUNICATION & COMPUTER NETWORK.pptxDATA COMMUNICATION & COMPUTER NETWORK.pptx
DATA COMMUNICATION & COMPUTER NETWORK.pptx
sanjutoppo93
 
Cloud Computingfor Librarian To Librarian Networking Summit
Cloud Computingfor Librarian To Librarian Networking SummitCloud Computingfor Librarian To Librarian Networking Summit
Cloud Computingfor Librarian To Librarian Networking SummitLynn McCormick
 
Cloud storage or computing & its working
Cloud storage or computing & its workingCloud storage or computing & its working
Cloud storage or computing & its working
piyush mishra
 
Introduction to Google Cloud Platform
Introduction to Google Cloud PlatformIntroduction to Google Cloud Platform
Introduction to Google Cloud Platform
dhruv_chaudhari
 
Cloud Computing Overview and Application
Cloud Computing Overview and ApplicationCloud Computing Overview and Application
Cloud Computing Overview and Application
IJSRED
 
Google Cloud Data Platform - Why Google for Data Analysis?
Google Cloud Data Platform - Why Google for Data Analysis?Google Cloud Data Platform - Why Google for Data Analysis?
Google Cloud Data Platform - Why Google for Data Analysis?
Andreas Raible
 
Extending Twitter's Data Platform to Google Cloud
Extending Twitter's Data Platform to Google CloudExtending Twitter's Data Platform to Google Cloud
Extending Twitter's Data Platform to Google Cloud
DataWorks Summit
 
Google Cloud Functions & Firebase Crash Course
Google Cloud Functions & Firebase Crash CourseGoogle Cloud Functions & Firebase Crash Course
Google Cloud Functions & Firebase Crash Course
Daniel Zivkovic
 
Cloud-based Energy Efficient Software
Cloud-based Energy Efficient SoftwareCloud-based Energy Efficient Software
Cloud-based Energy Efficient Software
Fotis Stamatelopoulos
 
Big Data Platform and Architecture Recommendation
Big Data Platform and Architecture RecommendationBig Data Platform and Architecture Recommendation
Big Data Platform and Architecture Recommendation
Sofyan Hadi AHmad
 

Similar to Optimizing cloud firestore reads (20)

GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
 
GDSC.pptx
GDSC.pptxGDSC.pptx
GDSC.pptx
 
Dannotes 50 - Collaboration Administration
Dannotes 50 - Collaboration AdministrationDannotes 50 - Collaboration Administration
Dannotes 50 - Collaboration Administration
 
Getting Started With Multi-Cloud Architecture by PM Integrated
Getting Started With Multi-Cloud Architecture by PM IntegratedGetting Started With Multi-Cloud Architecture by PM Integrated
Getting Started With Multi-Cloud Architecture by PM Integrated
 
Google Cloud Dataproc - Easier, faster, more cost-effective Spark and Hadoop
Google Cloud Dataproc - Easier, faster, more cost-effective Spark and HadoopGoogle Cloud Dataproc - Easier, faster, more cost-effective Spark and Hadoop
Google Cloud Dataproc - Easier, faster, more cost-effective Spark and Hadoop
 
DATA COMMUNICATION & COMPUTER NETWORK.pptx
DATA COMMUNICATION & COMPUTER NETWORK.pptxDATA COMMUNICATION & COMPUTER NETWORK.pptx
DATA COMMUNICATION & COMPUTER NETWORK.pptx
 
Cloud Computingfor Librarian To Librarian Networking Summit
Cloud Computingfor Librarian To Librarian Networking SummitCloud Computingfor Librarian To Librarian Networking Summit
Cloud Computingfor Librarian To Librarian Networking Summit
 
Cloud storage or computing & its working
Cloud storage or computing & its workingCloud storage or computing & its working
Cloud storage or computing & its working
 
Introduction to Google Cloud Platform
Introduction to Google Cloud PlatformIntroduction to Google Cloud Platform
Introduction to Google Cloud Platform
 
Cloud Computing Overview and Application
Cloud Computing Overview and ApplicationCloud Computing Overview and Application
Cloud Computing Overview and Application
 
Google Cloud Data Platform - Why Google for Data Analysis?
Google Cloud Data Platform - Why Google for Data Analysis?Google Cloud Data Platform - Why Google for Data Analysis?
Google Cloud Data Platform - Why Google for Data Analysis?
 
Extending Twitter's Data Platform to Google Cloud
Extending Twitter's Data Platform to Google CloudExtending Twitter's Data Platform to Google Cloud
Extending Twitter's Data Platform to Google Cloud
 
Google Cloud Functions & Firebase Crash Course
Google Cloud Functions & Firebase Crash CourseGoogle Cloud Functions & Firebase Crash Course
Google Cloud Functions & Firebase Crash Course
 
Final Presentation
Final PresentationFinal Presentation
Final Presentation
 
Cloud-based Energy Efficient Software
Cloud-based Energy Efficient SoftwareCloud-based Energy Efficient Software
Cloud-based Energy Efficient Software
 
Big Data Platform and Architecture Recommendation
Big Data Platform and Architecture RecommendationBig Data Platform and Architecture Recommendation
Big Data Platform and Architecture Recommendation
 

Recently uploaded

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 

Recently uploaded (20)

Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 

Optimizing cloud firestore reads

  • 2. Quick Definitions Firebase: The name of the suite of tools Google uses to provide BaaS (Backend as a Service) Real Time Database: Document based NoSQL used for smaller projects that require low latency Cloud FireStore: The new version of Real Time Database that is faster and more scalable Document: Holds data that contains a key that can be indexed and value associated with that key (Think table of contents that has a name of a chapter (Key) and a page number (Value)) Collection: List of documents
  • 3. Pricing Models Google charges users a fixed fee for every read, write and delete operation Google also charges for the amount of GB stored on their network Google offers three plans: - Spark: Free tier with limited daily usage - Flame: $25/month plan that stops charging if users go over a specific limit - Blaze: Pay-as-you-go plan that charges based on usage (See next slide) See https://firebase.google.com/pricing for more details
  • 4. Blaze Pricing Model Breakdown *price in USD [1]"Understand Cloud Firestore billing | Firebase", Firebase, 2019. [Online]. Available: https://firebase.google.com/docs/firestore/pricing. [Accessed: 15- Jul- 2019].
  • 5. Managing Reads and Writes Google sets the Blaze plan as default but it can be switched to any plan based on the users needs Since Google charges based on Read, Write and Delete operations there are strategies that can be used to minimize reads and writes and subsequently optimize your backend The goal is to give Google as little money as possible and avoid spending “$30,356.56 USD in just 72 hours” [8] [8]N. Contreras, "How we spent 30k USD in Firebase in less than 72 hours - By", Hackernoon.com, 2019. [Online]. Available: https://hackernoon.com/how-we-spent-30k-usd-in-firebase-in-less-than-72-hours-307490bd24d. [Accessed: 22- Jul- 2019].
  • 6. How Reads and Writes works Reads - When data is received from a document using get() or exist() - If data in a document is changed and client reads the update - If user logs out and logs back in after 30 minutes and reads the same data Writes - set() and update() are called - Everytime the data is manually changed in Cloud Firestore Deletes - Anytime a document is deleted or document field is deleted [1]"Understand Cloud Firestore billing | Firebase", Firebase, 2019. [Online]. Available: https://firebase.google.com/docs/firestore/pricing. [Accessed: 15- Jul- 2019].
  • 7. Strategies for Optimizing Reads and Writes Strategy 1: - Minimize hotspotting on Firestore Strategy 2: - Use Transactions and Batch Writes along with other Google recommended practices Strategy 3: - Follow Document Based NoSQL design patterns when modeling data
  • 8. Hotspotting Hotspotting: When one part of a system is being overloaded instead of being distributed across the whole system This occurs when: - Many documents are being created at once with incrementing/decrementing ids - Generating lots of documents in small collections - Adding data that frequently changes (i.e timestamps) - Deleting multiple documents in a collection - Writing to a document too frequently without gradually increasing traffic [2]"Best practices | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/best-practices#hotspots. [Accessed: 15- Jul- 2019].
  • 9. Minimizing hotspotting Document Ids - Avoid using the characters . .. and / - Do not use incrementing ids (i.e. Customer1, Customer2, Customer3 …) - Best to use a unique identifier such as a Username or email Field names - Avoid using periods, brackets, asterisk and backticks (Requires extra processing) Indexing - Avoid indexing as it increases storage costs - Only use indexing to partition or retreive expensive data (i.e large text file, large arrays) [2]"Best practices | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/best-practices#hotspots. [Accessed: 15- Jul- 2019].
  • 10. Following Google’s Best Practices Avoid writing more that one document per second - This can lead to high latency, timeouts or worse Use Asynchronous calls over synchronous calls Use cursors instead of offsets Use transactions and batch writes for reads and writes [2]"Best practices | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/best-practices#hotspots. [Accessed: 15- Jul- 2019].
  • 11. Transactions and Batch Writes Transactions and batch writes are used to perform atomic operations meaning it “guaranteed to be isolated from other operations that may be happening at the same time.” [3] Transaction is a set of reads and writes operations on one or more documents. [4] Batch write is a set of write operations on one or more documents. [4] [3]J. Fisher, "What the Heck Is an "Atomic Object"?", Atomic Spin, 2019. [Online]. Available: https://spin.atomicobject.com/2016/01/06/defining-atomic-object/. [Accessed: 15- Jul- 2019]. [4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
  • 12. Transactions A transaction is any get() operation followed by any set(), update() or delete() operation By using transactions data is guaranteed to be up to date and consistent Things to note: - Read operations must come before write operations - Transaction may be executed more than once if there are concurrent edits - Transaction should not directly modify the application state - Transactions will fail if the client is offline [4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
  • 13. Transaction in Python [4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
  • 14. Transaction Failure A transaction will fail if: - Transaction contains read operations after a write operation - A document was modified during a transaction. In this case the transaction will retry for a set number of times - Transaction size is greater than 10 MB Failed transactions does not write to firestore [4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
  • 15. Batch Write Batch writes allow you to write a combination set(), update() or delete() operations as a single atomic action. Batch write can hold up to 500 operations Other operations include serverTimestamp() , arrayUnion() and increment() Batch writes are less likely to fail and will not retry like transactions will Batch writes will execute even if the client is offline [4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
  • 16. Batch Write in Python [4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
  • 17. Designing Document Based NoSQL In traditional database tables have schema, a set on constraints the data must follow In Firestore, data is schema-less meaning it does not have to follow constraints [5]Microsoft, LocalDB used in Microsoft Visual Studio. 2019. [6]Medium, Document used in Firebase Firestore. 2019.
  • 18. Polymorphic Schema Because there are no constraints to follow we can put any type of data into a collection which makes the schema polymorphic or can take “many forms” [7] An example could be an online store that sells Appliances, CDs and Books Each item has similar attributes like price, name and quantity but also unique ones like: - Books have a Page Number - CDs have a Song Count - Appliances have a type such as Kitchen [7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
  • 19. Polymorphic Schema Since our online store will always be displaying the price, name and quantity to our users, the three products will be retrieved the same way Instead of a storing each product into separate collections for Books, CDs and Appliances it is better to have a products collection because the data is retrieved the same By simplifying our collections using a process known as denormalization, we reduce the number of reads and writes to our database Warning: Don’t over-simplify collections as it may reduce performance [7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
  • 20. One To Many Relationships One to Many: When an instance of an entity has one or more related instances of another entity [7] Examples include: - A Garage contains one or many cars - A shelf contains one or many books Suggested Practice: To put the multiple instances as a map or array inside the single instance [7] [7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
  • 21. One To Many Example Location Instance 1 Location Instance 2 Single Instance Customer [7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
  • 22. Many to Many Relationships Many to Many: When multiple instances of one entity are related to multiple instances of another entity [7] Examples Include: - Many students take many classes - Many doctors have many patients Suggested Practice: Use separate collections to represent the class of entities. Documents in the collection contain references to the data they are related to. [7] [7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
  • 23. Many to Many Example Courses Collection Students Collection Reference To Student Document Course Document Student Document Reference To Courses Document [7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
  • 24. Hierarchy Relationships Hierarchy: Instances of entities in some kind of parent-child or part-subpart relationship [7] Examples: - Creating a recliner, table and desk as parts of a furniture collection - Creating a lion, tiger and bobcat as children of a cat collection Suggested Practice: Give child entities a reference to the parent entities [7] [7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
  • 25. Hierarchy Example Parent Reference [7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217.
  • 26. Conclusion In my experience, following these guidelines will help: - Organize your data - Make faster queries - Create repeatable quality - Reduce costs Overall not just improving your user’s experience but your wallet’s experience as well
  • 27. References [1]"Understand Cloud Firestore billing | Firebase", Firebase, 2019. [Online]. Available: https://firebase.google.com/docs/firestore/pricing. [Accessed: 15- Jul- 2019]. [2]"Best practices | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/best-practices#hotspots. [Accessed: 15- Jul- 2019]. [3]J. Fisher, "What the Heck Is an "Atomic Object"?", Atomic Spin, 2019. [Online]. Available: https://spin.atomicobject.com/2016/01/06/defining-atomic-object/. [Accessed: 15- Jul- 2019]. [4]"Transactions and batched writes | Cloud Firestore | Google Cloud", Google Cloud, 2019. [Online]. Available: https://cloud.google.com/firestore/docs/manage-data/transactions#batched-writes. [Accessed: 15- Jul- 2019].
  • 28. References [5]Microsoft, LocalDB used in Microsoft Visual Studio. 2019. [6]Medium, Document used in Firebase Firestore. 2019. [7]D. Sullivan, NoSQL for mere mortals®. Hoboken [etc.]: Addison-Wesley, 2015, pp. 152 - 217. [8]N. Contreras, "How we spent 30k USD in Firebase in less than 72 hours - By", Hackernoon.com, 2019. [Online]. Available: https://hackernoon.com/how-we-spent-30k-usd-in-firebase-in-less-than-72- hours-307490bd24d. [Accessed: 22- Jul- 2019].