Introduction
TypeDB is a strongly-typed database that models data using entities, relations, and attributes organized in a type hierarchy. Its query language TypeQL uses declarative pattern matching with polymorphic inheritance, allowing you to write queries that work across type hierarchies without explicit joins or union types.
What TypeDB Does
- Models complex domains with entity types, relation types, and attribute types in a hierarchy
- Supports type inheritance and polymorphic queries across subtypes
- Uses TypeQL pattern matching to express complex queries declaratively
- Provides rule-based inference to derive new facts from existing data
- Enforces schema constraints (cardinality, ownership, role-playing) at the type level
Architecture Overview
TypeDB stores data in a custom storage engine optimized for traversing type hierarchies and relation hyperedges. The schema defines a type graph that the query planner uses to optimize pattern matching operations. Rules are compiled into query rewriting steps that materialize inferred facts on read. The server handles concurrent transactions with snapshot isolation and supports cluster mode for horizontal scaling.
Self-Hosting & Configuration
- Run via Docker or download platform-specific binaries from GitHub releases
- Default port is 1729 for client connections (gRPC-based protocol)
- Create databases and define schemas using TypeDB Console or client drivers
- Configure storage directory, server memory, and transaction timeout in config file
- Client drivers available for Python, Java, Node.js, Rust, and C++
Key Features
- Type inheritance enables polymorphic queries that adapt as your schema evolves
- Hyper-relations model n-ary relationships directly (not just binary edges)
- Rule-based inference derives implicit knowledge from explicit data
- Schema enforcement prevents data inconsistency at write time
- Declarative TypeQL eliminates the need for complex join logic
Comparison with Similar Tools
- Neo4j — Property graph with Cypher; TypeDB adds type hierarchies and inference rules
- PostgreSQL — Relational with rigid schemas; TypeDB models polymorphism natively
- RDF/OWL stores — Semantic web approach; TypeDB is more pragmatic with better DX
- Dgraph — GraphQL-native distributed DB; TypeDB focuses on type system and reasoning
- SurrealDB — Multi-model with SQL-like syntax; TypeDB is more opinionated about modeling
FAQ
Q: What kind of applications benefit from TypeDB? A: Knowledge graphs, drug discovery pipelines, fraud detection, and any domain with complex interconnected data and type hierarchies.
Q: How does inference work? A: You define rules in the schema (e.g., "if X is a parent of Y and Y is a parent of Z, then X is a grandparent of Z"). TypeDB materializes these at query time.
Q: Is TypeDB horizontally scalable? A: TypeDB Cloud (commercial) supports clustering. The open-source edition runs as a single server.
Q: Can I migrate from a relational database? A: Yes, but it requires rethinking your schema in terms of entities, relations, and attributes rather than tables and foreign keys.