Google Cloud: Introduction to Cloud Spanner

Share At:

What is Cloud Spanner?

  • Cloud Spanner is used to handle large amounts of data. It provides petabytes of capacity. Main use cases include financials and inventory applications.
  • Cloud Spanner can be considered a replacement for traditional SQL. For e.g. In a traditional database environment, when database query response times get close or even exceed the threshold limit due to an increase in the number of users or queries, you can bring response times down to acceptable levels through manual intervention.
  • Cloud Spanner can scale horizontally easily with minimal intervention. You can scale horizontally by just increasing the number of nodes (just change one digit).
  • Scaling horizontally means thousands of small machines will do the work together for you.
  • Scaling vertically means one big machine will do all the work for you.
  • Simply, Horizontal scaling implies scaling by adding more machines into your resource pool whereas Vertical scaling implies scaling by adding more power and strength to an existing machine.
  • For e.g multiple cloud-based POS solutions to retailers, restaurateurs, and eCommerce merchants around the globe.
  • Spanner is quite expensive than Cloud SQL.
  • For Cloud SQL you can select machine type, type of hard disk and size, region, and zone. You are restricted to have everything on one server.
  • Spanner is not for general SQL needs, Spanner is mainly used for massive-scale applications.

Lab Details:

  1. This lab walks you through Cloud Spanner.
  2. You will be creating a Spanner Instance and Database.

Lab Tasks:

  1. Login into GCP Console.
  2. Creating a Cloud Spanner Instance.
  3. Creating a Spanner Database.
  4. Create a Table.
  5. Inserting data into Table using SQL Query.
  6. Reading data through the Table using SQL Query.

Creating a Cloud Spanner Instance:

  1. Click on the hamburger icon on the top left corner
  2. Click on Spanner under the Databases section.

3. Click on Create Instance.

4. Enter the name as spanner-<your-title>. For e.g. If your title is dev then enter instance id as spanner-dev.

5. Choose the region configuration as Regional.

6. Choose region as us-central1.

7. Click on Create.

Creating a Cloud Spanner Database:

  1. Once the Instance is created, inside the instance, click on Create Database.

2. Enter the Database name as whizlabs-db.

3. Click on Create.

Creating a Table:

  1. Now click on Create Table.

2. You can either use UI mode or text mode, We are using UI mode in this case, Deselect the given option.

3. Enter the name of your table as employee_details and click on continue.

4. Click on the down arrow in Add Columns section.

5. Click on Add Column.

6. Add Column with name as id and given configuration. Click Done.

7. Add Column with name as name and given configuration.

8. Click Done. Click Continue.

9. Select primary key as id in set primary key section.

10. Click on Create.

Querying the table:

  1. Click on the Query tab in the left sidebar to enter any query.

2. Write the query INSERT INTO employee_details (id,name) values (1,”Martha”),(2,”Louis”),(3,”Linda”),(4,”Rachel”);

3. Click on Run.

4. You will see the result as 4 rows inserted.

5. Now you can use the select query to fetch the result select name from employee_details order by id desc;

6. Click on Run again.

7. You will see the output.

Completion and Conclusion:

  1. In this lab, you have created a Spanner Instance.
  2. You have created a Spanner Database
  3. You have created a Table.
  4. You have inserted data into the table using SQL Query.
  5. You have read the data from the table using SQL Query.

Happy Learning !!!


Share At:
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Back To Top

Contact Us