Dgraph Database Overview
Dgraph is a horizontally scalable and distributed GraphQL database with a graph backend. Dgraph is built for the heavy transactional workloads required to power modern apps and websites, but it isn’t limited to only these types of applications. Whether you are looking to power the backend of your app, create elastic search for your website, or build a new database purely for data analysis, Dgraph is up to the task. In fact, it is in production today in the following real-world scenarios:
- Data unification
- Customer 360
- Social media sites
- Content Management Systems
- Ecommerce stores
- Entity resolution
- HR management applications
- Master data management
- Product recommendation engines
- Real-time chat applications
To learn more about how organizations are using Dgraph, see Dgraph Case Studies.
How does Dgraph work?
Dgraph is not a layer on top of another SQL or No-SQL database such as Postgres or MongoDB. Instead, Dgraph is a new database built from the ground-up to manage data natively in graphs. Dgraph reads data from disk, accesses RAM, and talks over the network using HTTP and gRPC. A single Dgraph database instance consists of multiple entitles, described below in Dgraph architecture, but these three entities work together in a single layer.
What’s behind Dgraph’s GraphQL endpoints?
Dgraph is the world’s first, and at this time only, service to offer a specification-compliant GraphQL endpoint without the need for an additional translation layer in the tech stack. You will not find a hidden layer of GraphQL resolvers in Dgraph. GraphQL is natively executed within the core of Dgraph itself.
Dgraph Query Language (DQL)
Dgraph started out as its own proprietary graph database without support for the native GraphQL endpoint it has today. Early on, Dgraph engineers wanted to use GraphQL, but realized the official GraphQL specification could not support everything that customers would need from a database query language. GraphQL was not created to be a database query language, but it could easily be extended as a database query language.
So, Dgraph Labs forked our language from GraphQL and initially named this language GraphQL+- (“GraphQL, plus or minus”). For simplicity, GraphQL+- has since been renamed to Dgraph Query Language (DQL).
Dgraph and GraphQL
Dgraph was developed around DQL, which like GraphQL, uses a schema to classify and manage data. As Dgraph developed, it drew much attention from the GraphQL community, but developers still faced the challenge that has almost always been present when implementing GraphQL in a tech stack — the need to build a layer of GraphQL resolvers for queries, mutations, and subscriptions. The need for a layer of resolvers required developers to translate GraphQL into DQL, handling middleware, authorization, and custom business logic. Without a resolving layer, developers were not able to utilize the spec compliant, GraphQL community tools that continue to be developed.
In response to user feedback, Dgraph Labs decided to add a spec-compliant GraphQL solution into the core of Dgraph. But unlike other GraphQL solutions, Dgraph’s GraphQL implementation creates a spec-compliant GraphQL API with only developer-provided GraphQL schema. A developer defines types and fields, and applies directives in a GraphQL schema file that is provided to their Dgraph database instance. Dgraph then creates a full-featured CRUD-compliant GraphQL API endpoint, including the queries and mutations that one would expect when working with data under the provided GraphQL schema.
For more information about when and why to use either DQL or GraphQL and a side-by-side comparison, please see the GraphQL vs. DQL blog.
Dgraph is a single layer in your tech stack, but inside the inner workings of a Dgraph database instance, there are three distinct entities:
- Badger - Dgraph’s custom-built key-value store
- Ristretto - Dgraph’s custom-built cache
- Dgraph - the methods and algorithms used to parse DQL (and now GraphQL) and act accordingly
External to the core Dgraph database instance, you will find tools and communication clients to support Dgraph:
- Ratel - a GUI Layer to work directly with DQL. (Ratel does not work with the graphql)
Dgraph database clusters
Dgraph is designed specifically to distribute data horizontally. You can scale Dgraph and maintain high availability by sharding data and replicating those shards. Dgraph handles the mundane tasks of actually sharding and replicating the data, you just need to setup and configure your Dgraph cluster appropriately. For more information on deloying and managing Dgraph your self, see Production Checklist
Dgraph now offers a fully managed service with high availability. This relieves you from all the stress of deployment and relies upon our team of expert engineers. Continue reading this section for a quick overview of deployment, or skip to the next section to learn more about Dgraph Cloud, our fully managed Dgraph database-as-a-service offering
Running Dgraph database and Dgraph Cloud
You can run Dgraph database in a variety of ways:
- Fully-managed (hosted): Dgraph Cloud provides Dgraph as a fully-managed cloud service. Dgraph Cloud Shared Instances (formerly called Slash GraphQL) give you the power of Dgraph in a low-cost hosted service running on a shared cluster. Dgraph Cloud Dedicated Instances provide an enterprise-grade service that runs on dedicated cluster instances. To learn more, see Fully-Managed Dgraph.
- Self-managed: You can use Dgraph on-premises, hosted on your own physical infrastructure. You can also run Dgraph in your AWS, GCP, or Azure cloud infrastructure.
Dgraph Cloud with shared instances is a fully-managed GraphQL database service that lets you focus on building apps, not managing infrastructure. Dgraph Cloud is built from the ground up to support GraphQL, and uses a graph database structure down to its lowest layers. So it integrates seamlessly with your existing ecosystem of GraphQL tools.
Dgraph Cloud gives you the power of Dgraph database in a hosted environment, providing the flexibility and performance of a horizontally-scalable and distributed GraphQL database with a graph backend, so you don’t need to configure and manage VMs, servers, firewalls, and HTTP endpoints to power your modern apps and websites. Dgraph Cloud with shared instances runs on a shared cluster so we can offer it at a low price. To learn more about Dgraph Cloud, see Dgraph Cloud Overview.
Dgraph Cloud with dedicated instances extends the capabilities of the lower-cost shared instances offering to meet the heavy workloads and other needs of enterprise customers. With Dgraph Cloud, you get dedicated cluster instances, high availability, and the option to run Dgraph in your own virtual private cloud (VPC) or bring your own Kubernetes (BYOK) environment.
Use the instructions in this section to get started using Dgraph Cloud or self-managed Dgraph today.
Get started with Dgraph Cloud
Get started with self-managed Dgraph
To run Dgraph using the standalone Docker image
- Download docker: https://www.docker.com/
- Create a folder to store Dgraph data outside of the container, as follows:
mkdir -p ~/dgraph
- Get the Docker standalone image, as follows:
docker pull dgraph/standalone
- Run the Dgraph Docker standalone image, as follows:
docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 -p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph --name dgraph dgraph/standalone:v21.03.0
v21.03.0in the command shown above to the version number for a previous release, such as
After following these steps, Dgraph Alpha now runs and listens for HTTP requests on port 8080, and Ratel listens on port 8000.
Dgraph and GraphQL
Because Dgraph is a native GraphQL database, queries across sparse data sets run efficiently. As a native GraphQL database, Dgraph doesn’t have a relational database running in the background, so your data has the ability to grow and change with your app, without the need to add new tables. And when it comes time to deploy a new schema, you can do that in seconds, not hours.
Dgraph exposes a variety of HTTP and gRPC endpoints. The type of Dgraph cluster node that exposes each endpoint (Alpha or Zero) is noted with each endpoint description below:
/query- used to make query requests with DQL (Alpha)
/mutate- used to send mutations in DQL (Alpha)
/graphql- used to host the GraphQL API, rewriting GraphQL to DQL (Alpha)
/admin- used to administer the Dgraph cluster (Alpha)
/alter- used to alter the DQL schema (Alpha)
/health- used to query the health (Alpha)
/login- used to log-in an ACL user, and provides them with a JWT. (Enterprise Feature)
/state- used to view information about the nodes that are part of the cluster. (Zero)
/assign- used allocate a range of UIDs and request timestamps. (Zero)
/removeNode- used to remove a dead Zero or Alpha node from a cluster. (Zero)
/moveTablet- used to force move tablets to a group. (Zero)
/enterpriseLicense- used to apply an enterprise license to a cluster. (Zero)
Glossary of Dgraph and GraphQL terms
|Dgraph Cloud||A fully-managed GraphQL database service powered by Dgraph database.||Dgraph Cloud documentation|
|Badger||A fast, open-source key-value database written in pure Go that provides the disk layer for Dgraph database.||Badger documentation|
|data node||A basic unit of data representing an entity in a graph database. Nodes are connected by edges and have predicates (or fields) that contain node data.|
|Dgraph Alpha||A server node that serves data to clients of Dgraph database, and also provides administrator endpoints.||Dgraph Alpha documentation|
|Dgraph database||A horizontally-scalable and distributed GraphQL database with a graph backend.|
|Dgraph Query Language (DQL)||A query language that extends and modifies GraphQL to support deep queries for modern apps. Formerly known as GraphQL+-.||DQL documentation|
|Dgraph Zero||A server node that controls a Dgraph database cluster.||Dgraph Zero documentation|
|edge||A relationship between two data nodes in a graph database.|
|GraphQL||An open-source query language for APIs and a runtime for fulfilling those queries.||Dgraph GraphQL documentation|
|object||See data node.|
|server node||A server that makes up part of a server cluster. See Dgraph Alpha and Dgraph Zero.||Dgraph Cluster Setup documentation|
|superflag||A Dgraph CLI flag that contains one or more options used to specify command settings.||Dgraph Cluster Setup documentation|
|predicate||A property of a data node in a graph database; also a discrete piece of information available to request in a graph database.|