Introduction
Cayley is a graph database written in Go, originally created at Google and open-sourced for community use. It provides a flexible query layer supporting Gizmo (JavaScript-based) and GraphQL, backed by pluggable storage engines ranging from in-memory to PostgreSQL and MongoDB.
What Cayley Does
- Stores and queries graph-structured data using subject-predicate-object triples (quads)
- Supports multiple query languages: Gizmo (JS), GraphQL, and MQL
- Pluggable backend storage: BoltDB, PostgreSQL, MongoDB, in-memory, and more
- Provides a built-in web UI for visual graph exploration and query execution
- Imports and exports standard RDF formats (N-Quads, JSON-LD, Turtle)
Architecture Overview
Cayley uses a quad store model where each fact is stored as a quad (subject, predicate, object, label). The query layer compiles traversal expressions into an iterator-based execution plan that operates against a pluggable backend. Storage engines implement a common interface, allowing swaps between BoltDB for embedded use, PostgreSQL for durability, or in-memory stores for testing.
Self-Hosting & Configuration
- Install via Go toolchain or download prebuilt binaries from GitHub releases
- Configure storage backend with
--dbpathflag or YAML config file - Default HTTP port is 64210; override with
--hostand--portflags - Load initial data with
cayley load --quads=<file>supporting N-Quads and JSON-LD - Deploy with Docker using the official
cayleygraph/cayleyimage
Key Features
- Multiple query languages let teams pick what fits their mental model
- Pluggable backends mean you can start embedded and scale to PostgreSQL later
- Built-in web visualizer for interactive graph exploration
- Native Go library for embedding directly into Go applications
- RDF-compatible data model aligns with linked data standards
Comparison with Similar Tools
- Neo4j — More mature with Cypher, but requires JVM and commercial license for clustering
- Dgraph — Distributed GraphQL-native DB with higher operational complexity
- ArangoDB — Multi-model but heavier; Cayley is lighter for pure graph workloads
- Apache Jena — Full semantic web stack in Java; Cayley is simpler and Go-native
FAQ
Q: What query language should I start with? A: Gizmo (JavaScript-based) is the most documented and flexible for traversals. GraphQL works well if you already know your schema.
Q: Can Cayley handle large datasets? A: Yes, with PostgreSQL or MongoDB backends it handles millions of quads. For billions, consider a distributed graph DB instead.
Q: Is Cayley still maintained? A: The project has slower release cadence but remains functional and accepts contributions.
Q: Can I use Cayley as an embedded library? A: Yes, import the Go packages directly and use the graph API without running a server.