Content Published 2018
When to use graph databases
Graph databases are the most advanced tools for handling relationships between data at any level of complexity. What they offer over relational databases, the use cases that call for them — social networks, recommendations, fraud detection, knowledge graphs, science, network security — and what to check before choosing one.
Graph databases are designed specifically for the storage and traversal of relationships. They offer advantages over relational databases for use cases such as social networks, recommendation engines and fraud detection, where many relationships have to be created between data and queries run over them quickly.
Building this kind of application with a relational database involves certain difficulties:
- several tables with various related keys (foreign keys) are needed;
- the SQL queries for navigating this data would require nested structures and complex joins, which become awkward and inefficient as the quantity of data grows over time.
For these reasons graph databases (graph db or graph dbms) are enjoying enormous success, with three-digit growth rates:
Figure: the growth of graph databases.
Use cases
The use cases for graph databases are countless; these are the main ones.
Figure: social networks.
A graph database is able to process very many user profiles and interactions quickly and simply, in order to build social-network applications. Purpose-designed, standard query languages such as SPARQL allow highly interactive graph queries with a high throughput, to bring social features into your applications. For example, if you are building a social feed in your application, you can use graph-database queries to return results that prioritise, showing your users the latest updates from their relatives, from friends whose updates they “like”, and from friends who live near them.
Figure: recommendation engines.
A graph database lets you store the relationships between information — interests, friends and customers’ purchase histories — in a graph, and run queries quickly to create personalised and relevant recommendations. For example, you can use a graph database to create product recommendations for a user on the basis of the products bought by others who follow the same sport and have a similar purchase history. Or you can identify people who have a friend in common but do not yet know each other, and make friendship recommendations.
Figure: fraud detection.
You can use relationships to process financial and purchasing transactions practically in real time, to detect fraudulent activity patterns with ease. In a graph database it is possible to run fast graph queries to detect that a potential buyer uses the same email address and credit card as a known fraud case. If you are building a fraud-detection application in the retail sector, you can build graph queries to detect relationship patterns with ease — for example several people associated with one personal email address, or several people sharing the same IP address while residing at different physical addresses.
Figure: knowledge graphs.
Knowledge-graph applications are among the most important applications in existence today.
A knowledge graph helps you archive information in a graph model and use graph queries to let your users traverse highly connected datasets with ease.
Knowledge graphs are often the foundation of smart data management platforms and of next-generation semantic search engines, such as Google or IBM’s Watson.
For example, if a user is interested in the Mona Lisa, you can help them discover other works of art by Leonardo da Vinci, or other works of art held at the Louvre. Using a knowledge graph, you can add topical information to product catalogues, and build and run queries over complex models of regulatory rules or general information models such as Wikidata.
Figure: scientific applications.
A graph database helps you build applications that archive and traverse information in the scientific sector.
For example, to store models of interactions between diseases and genes, and to search graph patterns within protein pathways in order to identify other genes that might be associated with a disease. You can build models of chemical compounds as graphs and run pattern queries over molecular structures. It also helps to integrate information in order to address research challenges in the health and scientific fields. A graph database can be used to create and store data across different systems and to organise research publications topically, so that relevant information can be found quickly.
Figure: IT operations and network security.
You can use a graph database to store your network topology and use graph queries to answer questions such as how many hosts run a specific application.
A graph database is able to store and process billions of events in order to manage and protect your network. If you detect an anomalous event, the graph database lets you understand quickly how it can affect your network, by running queries for a graph pattern using the event’s attributes. You can run queries to identify other hosts or devices that may be compromised. For example, if you detect a malicious file on a host, the graph database can help you identify the links between the hosts that are spreading the malicious file and let you trace it back to the originating host that downloaded it.
Useful advice for choosing a graph database
There are many graph-database vendors. The first point to check is that they fully support the standards, in particular those promoted by the W3C within the web architecture — specifications such as RDF and SPARQL 1.1.
Some vendors implement their own query languages, binding users tightly to their products. Unless you have particular requirements, it is worth preferring those that support the standards.
It is common for vendors to extend the standards with proprietary functions. In this case too, if the use of the extensions is essential, it is worth considering encapsulating the queries that use them, so that maintaining the code stays simple.
Among the graph databases that fully support the W3C specifications, we point to:
- AWS Neptune, available “as a Service” but with some limitations in SPARQL Update
- Blazegraph, freely available and used by Wikidata
- OpenLink Virtuoso, one of the first and very widespread, though perhaps a little dated, with many additional functions, freely available
- Ontotext
- Stardog, used by NASA and other large organisations but very expensive
OK, I have a graph database. What now?
Before a database can be used it has to be populated with data. This operation is the most complex of all, because it requires assigning data a formal meaning.
Fortunately there are platforms such as SDaaS that help in this case too, importing data from the most common sources and making it possible to reuse languages, tools and data already available on the web.