What is Google Cloud Datastore in cloud computing and how to use it?

  1. Home
  2. Google
  3. What is Google Cloud Datastore in cloud computing and how to use it?
datastore

One of the most scalable NoSQL databases for apps is Google Cloud Datastore. When it comes to mobile and online apps, it has its own significance in the cloud computing business. Sharding and replication are supported by the Datastore. It also gives you with a highly available and durable database that scales automatically to handle the demand of your applications. Furthermore, it has features like as ACID transactions, SQL-like searches, indexes, and more.

Google Datastore Capabilities

Google Datastore is:

1. Simple and integrated

You can easily access any development target with Datastore’s RESTful interface. Moreover, it lets you create solutions that range across App Engine and Compute Engine and depends on Datastore as the integration point.

2. Fast and highly scalable

In Datastore, you can have complete focus on creating applications without any need to worry about provisioning and load anticipation. Further, this also helps in smooth and automatically scaling with data, thus giving applications access for maintaining high performance as they get more traffic.

3. Easy-to-use query language

A schemaless database might be considered Datastore. This is because it relieves you of the burden of worrying about making changes to your application’s underlying data structure as it grows. It also comes with a robust query engine that allows you to search data across different attributes and sort it as needed.

  • // List Google companies with fewer than 400 employees.
  • var companies = query.filter(‘name =’, ‘Google’).filter(‘size <‘, 400);

What are the features of Datastore?

Datastore is loaded with lots of features. Some of the top-mots features are:

1. Rich admin dashboard

Datastore dashboard provides access to view entity statistics, query your database, view indexes, and back up/restore your data.

2. Diverse data types

This comes with supports for a variety of data types. This also includes integers, dates, floating-point numbers, strings, and binary data, among others.

3. Multiple access methods

In Datastore, you can have access to data through JSON API, open-source clients, or community-maintained ORMs (Objectify, NDB).

4. ACID transactions

This feature Datastore ensures the integrity of your data by performing multiple datastore operations in a single transaction with ACID characteristics. This is so that all the grouped operations succeed or all fail.

5. Completely managed

Datastore can be considered fully managed. This is because Google automatically controls the sharding and replication in order for providing a highly available and consistent database.

In the next section, we will learn how to get started with Datastore using the database.

Getting Started with Datastore

In this, we will learn how to store and query data in Firestore in Datastore mode by using the Google Cloud Console.

Creating a database

For creating a new database instance, open the Datastore section in the Google Cloud Console:

Firestore: Native Mode or Datastore Mode

While creating a new Firestore database, you have the option to use Firestore in Native Mode or in Datastore mode.

Choose from one of the database options:

  • Firestore in Native Mode

Using Firestore in Native mode for mobile and web apps. 

  • Firestore in Datastore Mode

Using Firestore in Datastore Mode for new server projects. Choose Firestore in Datastore Mode for using the improved Firestore storage layer while keeping Datastore model system behavior.

Storing data

  • Firstly, in the Google Cloud Console go to the Datastore Entities page.
  • Secondly, click Create entity.
  • Next, if you see the following page, you need to select a location.
Screenshot of the Select a location page
Image Source: Google Cloud

For your Google Cloud project, the location is applied for both Datastore mode databases and App Engine apps.

  • After that, for saving a location, choose one of the location values and click Next.
  • Then, use [default] for Namespace on the Create an entity page.
  • Next, type Task for Kind.
  • Now, use the Add property button under Properties  for adding these properties:
Datastore
Image Source: Google
  • Lastly, click Create. The console shows the Task entity that you just created.

Running a query

Datastore mode databases query data by kind or by Google Query Language (GQL).

1. Run kind queries
  • Firstly, click Query by kind.
  • Secondly, choose Task as the kind.

Next, add a query filter for restricting the results to entities meeting specific criteria:

  • Firstly, click Filter entities.
  • Then, select done in the dropdown lists, is a boolean, and that is false.
  • After that, click Apply filters. The results display the Task entity created since its done value is false.
  • Lastly, try a query of done, is a boolean, and that is true. The results will not include the created Task entity because its done value is not true.
Run GQL queries
  • Firstly, click Query by GQL.
  • Secondly, enter SELECT * FROM Task as the query.
  • Then, click Run query.

Again, adding a query filter for restricting the results to entities meeting specific criteria:

  • Firstly, run a query like SELECT * FROM Task WHERE done=false. The results display the created Task entity since its done value is false.
  • Lastly, run a query like SELECT * FROM Task WHERE done=true. The results will not include the created Task entity, because its done value is not true.
Google Professional Data Engineer (GCP) online tutorials

Accessing your database 

In this, we will learn the process of accessing a Firestore in the Datastore mode database from different platforms including managing billing and spending limit. Talking about the Firestore in Datastore mode, this refers to a NoSQL document database created for automatic scaling, high performance, and proficiency of application development. However, Firestore is the latest version of Datastore and introduces many improvements over Datastore. And, by building a new Firestore in the Datastore mode database instance the existing Datastore users can access these improvements.

Accessing your database from App Engine

Datastore mode permissions for App Engine

By default, App Engine apps can have access to a Datastore mode database in the same project. Every App Engine app, on the other hand, employs an App Engine default service account to manage access to GCP services (Firestore). In addition, by default, the App Engine default service account has the Project Editor IAM role, which grants full read and writes access to Datastore mode. You may also update your App Engine default service account’s IAM permissions. However, unless an IAM role with the requisite Firestore permissions is assigned, this might result in application access to Firestore being lost.

Further, your App Engine app can lose access to your Datastore mode database if you disable or delete your App Engine default service account.

Accessing your database: Compute Engine instance

In this, we will learn how to activate and access a Datastore mode database from a Compute Engine VM instance in a new or existing project.

  • Firstly, enable the Google Compute Engine API for your project.
  • Secondly, ensure that billing is allowed for your Cloud project.
  • Thirdly, create a Compute Engine instance.

Console:

  • Firstly, go to the VM Instances page in the Google Cloud Console.
  • Secondly, click the Create instance button.
  • Thirdly, set Access scopes for providing access to Datastore in the Identity and API access section. Here, either click Allow full access to all Cloud APIs for provding access to all Google Cloud APIs, or click Set access for every API, click the dropdown for Datastore. After that, click Enabled for granting access to Datastore.
  • Fourthly, click the Create button for creating the instance.
  • Now, authenticate that your instance is running.
  • Lastly, for using this new Compute Engine instance, connect to it using your browser.
Accessing your database from another platform

In this, we will learn to access the Datastore mode database from an external application running on a platform outside of Google Cloud.

Creating a service account:

  • Firstly, go to the Create service account page in the Google Cloud Console.
  • Secondly, choose a project.
  • Thirdly, enter a name in the Service account name field. The Cloud Console fills in the Service account ID field depending on this name.
  • Then, click Create.
  • Now, click the Select a role field.
  • And, select a role that grants access to your database under All roles. This is like Datastore > Cloud Datastore User.
  • Click Continue.
  • Lastly, click Done for finishing creating the service account. But, do not close your browser window.

Creating a service account key:

  • Firstly, click the email address for the service account that you created in the Cloud Console.
  • Secondly, click Keys.
  • Thirdly, click Add key.
  • Then, create a new key.
  • After that, click Create. Here, a JSON key file will get downloaded to your computer.
  • Lastly, click Close.
Quotas and billing

A certain amount of free quota is available, this means you aren’t needed to enable billing for starting using Firestore in Datastore mode up to the free quota limits. However, if you require more resources than is provided by the free quota, then you must allow billing and set a spending limit for the project.

Enabling billing and setting a spending limit

The spending limit refers to the daily limit. This sets the maximum dollar amount of resources you will be billed for every day. After reaching the limit, no further costs will be incurred and no further billable Firestore in Datastore mode operations will be allowed. So, you have to define a spending limit because the initial default spending limit is always 0. That means you cannot exceed the free quota by default, even with billing enabled.

For enabling billing:

Firstly, ensure that billing is enabled for your Cloud project.

Then, for setting a spending limit:

  • Go to the Application settings.
  • Then, click Edit and define a spending limit.
  • Click Save.

However, the spending limit applies to App Engine resources only which includes Firestore, for the selected project:

  • So, you may still be billed for other Google Cloud Platform resources.
  • And, if you have multiple projects, then set the spending limit for each project.

Pricing

The basic pricing structure of datastore is:

datastore pricing
Image Source: Google Cloud

Final Words

Above we have understood the concept of Google Cloud Datastore by learning about its features, uses, and how to get started with this service. However, Google Datastore is providing solutions to many top companies using its No-SQL database for scaling web and mobile applications. So, if you have an interest in getting started with this service, then go through the blog and use the Google documentation for having more clarity with the concepts.

Google Professional Data Engineer (GCP) practice tests
Menu