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 edges.
Graph Elements
A graph consists of the following primary elements:
- Nodes (or vertices), which represent entities (e.g.,
User
,Book
,Country
). - Edges, which represent relationships between entities (e.g.,
rate
,purchased
,locate_in
).
Nodes are uniquely identified by the system property _id
(string type). Every edge is associated with a source node and a destination node, whose _id
values are stored in the edge's system properties _from
and _to
, respectively. These properties also define the direction of the edge.
Graph Structure
Before creating a graph, it is essential to design an appropriate graph structure (or model) based on the specific scenario.
A graph structure is defined by:
- Types (or Labels, Schemas), which refer to specific types for nodes and edges. Each node or edge is assigned exactly one type.
- Properties, which are associated with node and edge types storing attributes about nodes and edges. Each property has a specific type that defines the nature of its values. For example, a
User
node might have properties likename
(string type) andage
(int32 type).
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 navigating through the graph by moving from one node to another via edges. This is similar to the JOINs in relational databases to link related data. However, graph database traversal is far more efficient because relationships are inherently stored within the graph. This makes graph databases ideal for scenarios requiring rapid exploration of interconnected data, even for deep traversals spanning 5, 10, 20, or more hops.
When to Use Graph Databases
Graph database is a versatile, general-purpose database designed to model diverse scenarios, including but not limited to, financial systems, supply chain management, and social networks. It particularly excels 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 querying capabilities make it easier to express and analyze intricate patterns and connections.