The graph (Gremlin) data model

In SQL database, we have rows and columns; in NoSQL, we have a key and value-based document, and in big data, we have column and data.

However, none of these models are directly mapped to real-world objects. Graph databases are built to bridge this gap.

A graph data model is a structure that's comprised of vertices and edges. Both vertices and edges can have a set number of properties. Vertices represent discrete objects, such as a person, a place, or an event. Edges represent relationships between vertices. For example, a person might know another person, be involved in an event, and may have recently been at a location. Properties denote details about the vertices and edges. Azure Cosmos DB supports the property graph model.

For example, consider the following graph:

One of the important use cases of the graph is to find relations between entities. For example, if I am friends with someone, then using the vertices, we can recommend their friends to us, similar to the Friends you may know feature of Facebook.

Graphs are also useful in major data science exploration. Complex algorithms are built on top of the graph database to obtain a sense of huge data.

Let's look at some of the features that graph databases in Cosmos DB provide:

  • Elastic scale: Effectively scale up or downsize your graph database to meet your application needs. Your information is stored on an SSD for low latency. Cosmos DB supports the Graphlin API format.
  • Replication: As you have learned in the last chapter, Cosmos DB data models, such as graphs, can be replicated across any number of regions supported in the Azure data center. This provides us the ability to develop globally available applications with as low latency as possible. Cosmos DB also provides failover handling whether it's automatic or manual as discussed in Chapter 2, Cosmos DB Global Turnkey Distribution.
  • Fast query traversal: You can use the Graphlin syntax to create and store graphs and query them with single digit latency with Cosmos DB.
  • Fully managed: You don't need to install or run the graph daemon or server anymore. It is fully managed by Microsoft. Fear of restarts, crashes, and being out of memory are no more!
  • Automatic indexing: Cosmos DB indexes all properties within the nodes and edges of a graph for a faster response time and low latency.

Let's go ahead and create a new graph database in Cosmos DB:

  1. Log in to your Azure portal and click on the Azure Cosmos DB option on the left side of the option bar.
  2. Click on the + button and give your new database a proper ID, choose the Gremlin (graph) option from the API drop down.
  1. You can create a new resource or use the existing one. Select the location where the most writing will happen and click on the Create button. You can refer to the following screenshot for further information:
  1. Once the graph data model is created, we can create new databases and graphs in it and store the data.
  2. Go to Data Explorer on the left menu and click on the New Graph button.
  1. Give your database and graph ID a name and click on the OK button. Refer to the following screenshot for further information:
  1. Once the database is created, you can create a new vertex. Click on the New Vertex button and give it a label, say, a laptop.
  2. Click on New Vertex again and create a new vertex, say, John. In relation, we will say, John uses Laptop. You can open the properties by clicking on the second vertex from the graph.
  1. Go to Targets, and choose the laptop vertex as a target. Refer to the following screenshot for further information:

Once it is created, you shall see the graph connected as shown in the following image:

This is awesome! We can indeed create more vertexes and connect them together and query it to get some useful information.

We will do more graph queries in the coming chapter that is, Chapter 4, Querying Cosmos DB.

Let's look at the Cassandra API supported by the Cosmos DB.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.155.130