Understanding Infrahub’s schema system
Infrahub’s schema system provides a flexible, declarative way to define your infrastructure data model. Unlike traditional databases with rigid, single schemas, Infrahub allows different schemas per branch and stores the schema itself as data in the graph database. This design enables schema evolution, versioning, and experimentation without disrupting production environments.Why a flexible schema matters
Infrastructure data models vary significantly across organizations. A network team managing a data center fabric has different needs than a cloud team orchestrating Kubernetes clusters. Infrahub doesn’t impose a rigid schema—instead, it provides a flexible foundation you can adapt to your specific requirements. This flexibility delivers several benefits:- Customization: Model your infrastructure exactly as it exists, without forcing it into predefined structures
- Evolution: Change your data model as your infrastructure grows and transforms
- Experimentation: Test schema changes in branches before applying them to production
- Reusability: Share common patterns through generics while maintaining specific implementations
- Validation: Enforce data quality through constraints and relationships at the schema level
Core concepts
Schema as data
Infrahub stores the schema itself in the graph database, treating it like any other object. This architectural decision enables powerful capabilities:- Each branch can have its own schema version
- Schema changes follow the same branching and merging workflow as data changes
- Schema history is preserved with full audit trail
- Schema migrations run automatically during branch operations
The four building blocks
Infrahub schemas consist of four primary types: Nodes represent concrete objects in your infrastructure. Each node has attributes (direct values like text or numbers) and relationships (connections to other nodes). Nodes are the entities you create, query, and manage.Attribute: Related entities appear in list and detail viewsComponent: Related entities appear in separate tabs, with cascade deletionParent: Hierarchical relationships that enable filtering and organizationGeneric: Flexible relationships without specific functional significance
Router node inherits name and description from GenericDevice and adds its own routing_protocol attribute.
Schema namespaces and kinds
Every node and generic has a namespace and name. Together, these form the “kind”—a unique identifier for the schema element:Core, Infrahub, Profile, Builtin) are used by the system and cannot be used for custom schemas. This separation ensures your schema doesn’t conflict with internal objects.
Architecture and design decisions
Declarative and incremental
The schema format is declarative—you describe what you want, not how to create it. It’s also incremental, meaning you can load schema fragments from multiple sources that compose into a complete schema. To explicitly remove a schema element, usestate: absent:
Branch-aware, agnostic, and local
Schema elements can operate in three branching modes: Branch-aware (default): Changes are local to the branch and can be merged. This mode supports the standard branching workflow—changes in feature branches merge into main through proposed changes. Branch-agnostic: Changes are immediately visible in all branches. This mode is useful for system-level configurations and reference data that should remain consistent across all branches:- Attributes inherit their node’s branch mode
- Relationships become branch-agnostic only if both connected nodes are branch-agnostic
Schema validation and migration
When you update a schema, Infrahub automatically validates existing data against the new schema and performs necessary migrations. This process occurs:- When loading a schema into a branch
- During proposed change validation
- When rebasing a branch
- When merging branches
- Required attributes must have values
- Unique constraints must not have duplicates
- Relationships must reference valid nodes
- Attribute types must match the data
Implementation examples
Human-friendly identifiers (HFID)
Infrahub generates UUIDs for internal object identification, but infrastructure teams need human-readable identifiers. Thehuman_friendly_id property defines which attributes compose a unique, readable identifier:
(router-1, eth0) that uniquely identify interfaces based on device name and interface name. HFIDs enable:
- Idempotent scripts that reference objects before they exist
- Data synchronization between systems
- GraphQL upsert operations using readable identifiers
Uniqueness constraints
Complex uniqueness requirements beyond single attributes useuniqueness_constraints. For example, ensuring each person owns at most one car model:
Hierarchical schemas
Some infrastructure naturally forms hierarchies—locations (region → country → city) or organizational structures. Hierarchical mode enables querying across these relationships:parent, children, ancestors, and descendants relationships. In GraphQL, you can query members of a group including all descendant groups:
Menu organization
The schema controls how models appear in the frontend sidebar:Schema evolution patterns
Loading schemas
Schemas can be loaded through multiple methods: Via infrahubctl:.infrahub.yml:
Renaming schema elements
Namespace and name form the identifier, so renaming requires providing the internal UUID temporarily:/schema in the frontend.
Schema strict mode
By default, Infrahub runs all schema validators on every change. When upgrading versions that introduce new validators, you may need to temporarily disable strict mode:- Relationships same parent constraint
- Min/max value and length comparisons
- HFID uniqueness requirements
- Number attribute constraint validation
Design trade-offs
Flexibility vs. performance
Storing schema as data provides flexibility but adds complexity. Schema queries require database access, and schema changes trigger validation and migration. Infrahub mitigates this through aggressive caching—the SchemaManager maintains an in-memory cache of branch schemas with LRU eviction. The performance trade-off is worthwhile for infrastructure management, where schema changes are infrequent but the ability to version and branch schemas is invaluable.Generic inheritance limitations
Generics propagate properties to nodes only during first import. Subsequent generic updates don’t automatically update implementing nodes. This limitation simplifies the system—nodes have stable properties that don’t change unexpectedly when generics update. If you need to update node properties after changing a generic, explicitly update each node.Validation timing
The default branch enforces comprehensive validation to ensure production data quality. Feature branches relax some constraints for development speed. This creates a trade-off: faster iteration in branches but validation errors may appear later during merge. Proposed Changes validate thoroughly before merge, catching issues before they reach production.Related topics
- Branching - How schema changes flow through branches
- Version Control - Schema history and time travel
- Graph Database - How schemas map to the graph structure