Contents
Introduction to Google Cloud Firestore
Picking the right database solution on Google Cloud Platform can be tricky. There are so many options to choose from, and sometimes the differences between them are not very obvious. In this course, you will learn about Firestore, one of Google’s NoSQL databases. We will cover what it can do, how it differs from some other databases, and how to get started using it.
Learning Objectives
- Understand what Google Cloud Firestore is
- Learn how to use it to store and retrieve data
- Know how to create indexes
- Know how to install the emulators for local development
Intended Audience
- Database administrators
- Cloud Architects
- GCP Developers
- Anyone preparing for a Google Cloud certification
Prerequisites
- Some experience with databases and writing queries
When you are first learning to use Firestore, it can be very easy to get confused. Google has not done the best job of differentiating it from some similar products. For example, if you research Firestore you might stumble across similar sounding products such as Datastore and Firebase. So in this lesson, we are going to cover a little bit of history. This should help you understand where Firestore came from, as well as how it relates to these similar sounding products.
Prior to Firestore’s release, Google offered a database called Datastore. Datastore was built specifically to use with App Engine. The basic idea was that since App Engine could support massive scaling, they also needed a database that could keep up with it. Then in 2014, Google acquired a product called Firebase. Google took some of the advanced storage technology from Firebase, combined it with Datastore, and ended up creating Cloud Firestore.
Firestore was meant to be the next-generation update to Datastore, but a lot of apps had already been built that use Datastore. So in order to support this, Firestore was built with two different modes: Datastore and Native. Datastore mode is essentially a “Datastore compatibility mode” for Firestore. In this mode, data is kept in Firestore’s storage layer, but it is still accessible using the Datastore API. In this way, developers could continue to use their Datastore tables in the same manner as before. And they could also continue to create new Datastore-compatible tables if they needed.
However, developers now also had the option of using the improved Firestore Native mode. Native mode stores your data in Firestore’s storage layer, and it allows you to use the new Firestore API to access your data. This gives you extra features such as real-time updates and offline synchronization. So whichever mode you choose, you are actually using Firestore. The main difference being whether you want to emulate Datastore or not.
Just to further complicate things, I do need to mention that even though Firestore came from Firebase, Firebase still exists as a Google product. Now, this is where it gets really confusing. Firebase is both a database technology and a complete application development platform. Firebase (the platform) includes a component called the Firebase Realtime Database. Also when developing on Firebase, you can choose to use Firebase (the database) or you can use Firestore.
If by chance anyone from Google marketing is currently listening, your naming scheme is pretty confusing. I mean, sure these names make sense when you understand the history, but they also make things unnecessarily complicated for anyone just starting out.
So for those of you who are confused, let me try to summarize. First, there was a NoSQL database called Datastore. Then Google acquired a development platform (including a database) called Firebase. Google took the storage technology from Firebase, combined it with Datastore, and created a new noSQL database called Firestore.
Now Firestore can operate in one of two modes: Datastore mode and Native mode. And it is important to understand the differences between the two, because each Google project can only use one mode. You cannot have both a Native and a Datastore mode database in the same project.
Now if you are already working on an existing application that requires a particular mode, your decision is easy. However, if you are starting from scratch, then choosing between the two can be more difficult. Firestore in Native mode is optimized for mobile and web applications. It has client libraries that offer both real-time and offline synchronization. So this means it can access a local cache of your data when you go offline. Plus it will automatically sync any changes to the cloud when your web connection is re-established.
Firestore in Datastore does not have these features. Instead it is optimized for server-side processing. So the short answer is: if you don’t need any of the mobile or web features, then you should probably choose Datastore mode. The long answer is a bit more complicated. The two modes work a bit differently. Datastore mode uses entities and kinds for its data model. Where Native mode organizes things into documents and collections. So depending on how you need to organize and query your data, one model might fit better than that other. Also pricing is handled differently. So ultimately, you might need to evaluate both modes to determine which is the best fit for your project.
Daniel began his career as a Software Engineer, focusing mostly on web and mobile development. After twenty years of dealing with insufficient training and fragmented documentation, he decided to use his extensive experience to help the next generation of engineers.
Daniel has spent his most recent years designing and running technical classes for both Amazon and Microsoft. Today at Cloud Academy, he is working on building out an extensive Google Cloud training library.
When he isn’t working or tinkering in his home lab, Daniel enjoys BBQing, target shooting, and watching classic movies.