A graph database is a type of database that stores, queries, and manages data in the form of graphs instead of tables or documents. It enables you to organize data in an intuitive way that aligns with how we naturally think, and this structure makes querying and analyzing highly connected data much easier and more efficient.
What is a Graph
An instance of the Ultipa graph database can host one or more graphs, each representing a unique dataset or domain of interconnected nodes and relationships.
Graph Elements
A graph consists of nodes and edges as its primary elements:
- A node (or vertex) typically represents an entity (e.g.,
User
,Book
,Country
). - An edge represents the relationship between two entities (e.g.,
rate
,purchased
,locate_in
). Each edge must have a source node and a destination node, which also defines its direction.
Graph Structure
Before creating a graph, it is essential to design an appropriate graph structure based on the specific scenario.
A graph structure is defined by:
- Labels (or Schemas), which refer to specific types for nodes and edges. Each node or edge is assigned exactly one label.
- Properties, which are associated with labels that store attributes about nodes and edges. For example, a
User
node might have properties likename
andage
.
The graph structure can evolve over time and is subject to flexible changes.
Paths
A path in a graph is a sequence of an odd number of connected graph elements. A path always:
- starts and ends with a node, and
- alternates between nodes and edges.
A path may comprise a single node. In Ultipa, a path allows nodes to be revisited but not edges by default.
How Graph Databases Work
It has been established that graph databases consist of nodes and edges. Traversing is the act of journeying through a graph by visiting nodes via edges. This is similar to the JOINs on the relational database tables to connect related data. However, graph database traversal is significantly faster because relationships are inherently stored within the graph. This efficiency makes graph databases well-suited for scenarios that require quick exploration of interconnected data.
When to Use Graph Databases
Graph database is a versatile, general-purpose database designed to model diverse scenarios such as financial systems, supply chain management, social networks. They excel in cases involving highly connected data, where the relationships between data points are as important as the data itself.
By natively storing and managing these relationships, graph databases eliminate the need for complex and costly table joins, delivering superior performance. Furthermore, their advanced query capabilities make it easier to express and analyze intricate patterns, paths, and connections.