Library

Volume 2 · Knowledge Graphs

Notebook
Sign in

Section 37

Ontology / Schema Design

485 words · about 2 min

37.1 Design Process

Step 1 — Domain scoping. Define the purpose: what questions must the graph answer? Identify core entity types and relationships. Determine granularity.

Step 2 — Conceptual modeling. Worked example — an IT service-management ontology:

Entity Types:
├── Service (Microservice, API, Database, Queue)
├── Infrastructure (Cluster, Node, Container, VM)
├── Team (Engineering, Operations, Security)
├── Incident (Alert, Outage, Degradation)
├── Change (Deployment, ConfigChange, ScaleEvent)
├── Dependency (Runtime, Build, Data, Network)
└── SLA (Objective, Measurement, Violation)

Relationship Types:
├── Service → DEPENDS_ON → Service
├── Service → DEPLOYED_ON → Infrastructure
├── Service → OWNED_BY → Team
├── Incident → AFFECTS → Service
├── Incident → TRIGGERED_BY → Change
├── Change → DEPLOYED_BY → Team
├── Service → HAS_SLA → SLA
└── Team → RESPONSIBLE_FOR → Service

Step 3 — Schema formalization (Neo4j example):

// Node constraints and indices
CREATE CONSTRAINT service_id IF NOT EXISTS
FOR (s:Service) REQUIRE s.service_id IS UNIQUE;

CREATE CONSTRAINT team_id IF NOT EXISTS
FOR (t:Team) REQUIRE t.team_id IS UNIQUE;

CREATE INDEX service_name IF NOT EXISTS
FOR (s:Service) ON (s.name);

// Schema enforcement (Neo4j 5+)
CREATE NODE KEY Service(service_id);
CREATE PROPERTY TYPE Service.name AS STRING NOT NULL;
CREATE PROPERTY TYPE Service.criticality AS STRING;

37.2 Schema Evolution Strategies

  1. Additive changes — add new node/edge types and properties freely; this is the cheapest, safest kind of change.
  2. Property deprecation — mark properties deprecated, migrate data gradually rather than removing them outright.
  3. Version tracking — store an ontology version in graph metadata so downstream consumers can detect drift.
  4. Migration scripts — Cypher (or SPARQL update) scripts for schema transitions, tracked and reviewed like any other migration.
  5. Backward compatibility — support old and new schema shapes during a transition window rather than a hard cutover.

Section 37 — Interview Q&A

Q1: Walk through your process for designing an ontology for a new domain. Start with domain scoping — what specific questions must the graph answer (this drives which entities and relationships are worth modeling — don’t model everything that theoretically exists, model what’s queried). Then conceptual modeling — enumerate entity types and their relationships at a whiteboard level, checking for MECE coverage of the domain. Then formalize the schema with constraints, uniqueness keys, and indices on the properties that will actually be filtered/joined on. Finally, version the ontology from day one so evolution is a first-class, trackable process rather than an undocumented drift.

Q2: How do you evolve a knowledge graph schema without breaking existing consumers? Favor additive changes (new node/edge types, new optional properties) which never break anything. For anything that must change destructively — renaming a relationship type, removing a property — use a deprecation cycle: introduce the new shape alongside the old, dual-write during a transition window, migrate consumers, then remove the old shape only after confirming no reads remain against it. Track ontology version explicitly in graph metadata so any consumer can detect and adapt to which schema version it’s reading.