Property Graph against RDF, and Choosing a Model

Article · 9:00

Vertices and edges against triples, identifiers, the modelling differences that matter, bulk loading each, and how to choose.

This is the module that cannot be deferred, because the two stores are separate and the choice is not reversible without a reload and a rewrite.

The property graph model is the Neo4j-shaped one: vertices with labels and properties, edges with a label and properties, directed. Identifiers are opaque strings you supply or Neptune generates. One difference from Neo4j worth knowing: Neptune's property graph allows an edge to have only one label, as Neo4j does, but a vertex can have several labels only in openCypher, and Gremlin treats a multi-label vertex differently - which is one of several places the two languages see the same store slightly differently.

The RDF model is triples: subject, predicate, object. Everything is identified by an IRI - a global identifier that looks like a URL - and an object may be another IRI or a literal with a datatype. There are no properties on relationships: (:alice) (:knows) (:bob) has nowhere to put "since 2024", and the standard answer is reification - making the statement itself a resource with its own triples - which works and is verbose. Triples can be grouped into named graphs, giving you a fourth element (a quad) and a natural way to partition by source or version.

What RDF gives you that the property graph does not:

  • Global identifiers. An IRI is meaningful outside your database, so two datasets that both use schema.org/Person genuinely interoperate. This is the single strongest argument for RDF and it only matters if you are actually integrating external data.
  • Standard vocabularies - RDFS, OWL, SKOS, Dublin Core, schema.org - so your schema is something you adopt rather than invent.
  • Inference, where a reasoner derives implied triples from a vocabulary. Neptune's inference support is narrower than the RDF ecosystem implies - check the current documentation rather than assuming OWL reasoning - and designs that depend on heavy inference are usually disappointed here.
  • SPARQL's federation (SERVICE), which queries a remote endpoint as part of your query.

What the property graph gives you:

  • Properties on edges, without reification. For a transaction amount, a relationship weight or a validity period, this is a large practical advantage.
  • A more natural fit for application data that is not meant to interoperate with anyone.
  • Two query languages, one of which (openCypher) you may already know.

How to choose, in order:

  1. Are you integrating external, standards-based data, or publishing data for others to integrate? If yes, RDF. This is the question that settles most cases.
  2. Do your relationships carry data? If yes, and the answer to (1) was no, property graph.
  3. Does your team know Cypher? openCypher on a property graph is then the lowest-friction choice.
  4. Do you need inference? Check what Neptune actually supports before letting this decide anything.

Bulk loading differs per model: CSV with ~id/~label headers for Gremlin, :ID/:LABEL for openCypher, and N-Triples, N-Quads, Turtle or RDF/XML for SPARQL.

Laboratory exercise 2 - two models, implemented.

Write the query list for the capstone's identity resolution graph - at least ten queries, numbered.

Implement the same domain twice: once as a property graph and once as RDF, in the same cluster. This is the exercise, and it is more work than it sounds - which is the point, because it is the work you would redo if you chose wrongly.

Implement every query in all three languages where the model allows: Gremlin and openCypher against the property graph, SPARQL against the RDF store. For any query a model cannot express naturally, implement the workaround and record what it cost.

Specifically demonstrate the reification problem: put a confidence score and a created_at timestamp on a "same person as" relationship. In the property graph it is two edge properties. In RDF, implement it by reification and record the triple count for each.

Bulk load both models from S3 and record the format differences, the load times and the resulting storage size.

Then test inference: load a small RDFS vocabulary, write a query that depends on rdfs:subClassOf inference, and record exactly what Neptune does and does not infer.

Deliverable: the numbered query list, both models implemented with a diagram of each, every query in each applicable language, the reification comparison with triple counts, the two load formats with times and sizes, the inference test with its actual result, and a page choosing one model with the reasoning from the four questions.

# ==================================================================
# THE PROPERTY GRAPH: vertices, edges, properties. Neo4j-shaped.
# ==================================================================
%%gremlin
g.addV('Person').property(id, 'p-0001')
   .property('name', 'Ada Lovelace')
   .property('email', 'ada@example.test')
   .next()
g.addV('Email').property(id, 'e-ada').property('address', 'ada@example.test').next()
g.V('p-0001').addE('HAS_EMAIL').to(__.V('e-ada'))
   .property('verified', true)
   .property('since', '2024-01-01').next()
#                     ^^^^^^^^^^^^ *** PROPERTIES ON THE EDGE. ***
#                     Remember this when you reach RDF below.

%%oc
// The SAME store, a different language:
MATCH (p:Person {`~id`: 'p-0001'})-[r:HAS_EMAIL]->(e:Email)
RETURN p.name, e.address, r.verified, r.since

# ONE DIFFERENCE WORTH KNOWING: a vertex can carry SEVERAL LABELS,
# and GREMLIN AND openCYPHER SEE THAT DIFFERENTLY - Gremlin's
# label() returns them joined, openCypher's labels() returns a list.
# It is one of several places the two languages see the same store
# slightly differently, and it will catch you once.

# ==================================================================
# THE RDF MODEL: subject, predicate, object. Everything is an IRI.
# ==================================================================
%%sparql
PREFIX ex:     <http://example.test/>
PREFIX foaf:   <http://xmlns.com/foaf/0.1/>
PREFIX xsd:    <http://www.w3.org/2001/XMLSchema#>
INSERT DATA {
  ex:p-0001 a foaf:Person ;
            foaf:name "Ada Lovelace" ;
            foaf:mbox <mailto:ada@example.test> .
}
#   ex:p-0001 is an IRI - A GLOBAL IDENTIFIER, meaningful OUTSIDE
#   your database. foaf:Person is a STANDARD VOCABULARY TERM, so two
#   datasets that both use it genuinely interoperate.
#   *** THAT IS THE SINGLE STRONGEST ARGUMENT FOR RDF, and it only
#   *** matters if you are ACTUALLY integrating external data. ***

%%sparql
SELECT ?name ?mbox WHERE {
  ex:p-0001 foaf:name ?name ;
            foaf:mbox ?mbox .
}

# NAMED GRAPHS: a fourth element (a quad), and a natural way to
# partition by SOURCE or VERSION - which is genuinely useful for
# identity resolution, where provenance matters:
%%sparql
INSERT DATA {
  GRAPH ex:source-crm {
    ex:p-0001 foaf:name "Ada Lovelace" .
  }
  GRAPH ex:source-billing {
    ex:p-0001 foaf:name "A. Lovelace" .
  }
}
%%sparql
SELECT ?g ?name WHERE { GRAPH ?g { ex:p-0001 foaf:name ?name } }
#   TWO conflicting names, each attributed to its source. The
#   property graph has no built-in equivalent - you would add a
#   `source` property and lose the ability to query by graph.

# ==================================================================
# *** THE REIFICATION PROBLEM. Demonstrate this one. ***
# ==================================================================
# RDF HAS NO PROPERTIES ON RELATIONSHIPS. This statement:
#     ex:p-0001  ex:sameAs  ex:p-0042
# has NOWHERE to put "confidence 0.87, created 2026-11-30".
#
# PROPERTY GRAPH - two edge properties, one edge:
%%gremlin
g.V('p-0001').addE('SAME_AS').to(__.V('p-0042'))
   .property('confidence', 0.87)
   .property('created_at', '2026-11-30')
   .property('method', 'email_match').next()
#   1 edge, 3 properties.

# RDF - REIFICATION. The statement becomes a RESOURCE:
%%sparql
INSERT DATA {
  ex:match-001 a rdf:Statement ;
      rdf:subject   ex:p-0001 ;
      rdf:predicate ex:sameAs ;
      rdf:object    ex:p-0042 ;
      ex:confidence "0.87"^^xsd:decimal ;
      ex:createdAt  "2026-11-30"^^xsd:date ;
      ex:method     "email_match" .
  ex:p-0001 ex:sameAs ex:p-0042 .
}
#   *** 7 TRIPLES instead of 1 edge with 3 properties. *** And every
#   query about the match's confidence must now join through the
#   statement resource:
%%sparql
SELECT ?a ?b ?conf WHERE {
  ?stmt rdf:subject ?a ; rdf:predicate ex:sameAs ; rdf:object ?b ;
        ex:confidence ?conf .
  FILTER(?conf > 0.8)
}
#   It works, it is verbose, and it is slower. COUNT THE TRIPLES in
#   the lab - that ratio is the clearest single argument for the
#   property graph when your relationships carry data.
#   (RDF-star / RDF 1.2 addresses this; check Neptune's support for
#    it rather than assuming.)

# ==================================================================
# SPARQL's real strengths: joins, OPTIONAL, and FEDERATION.
# ==================================================================
%%sparql
SELECT ?person ?name ?email ?phone WHERE {
  ?person a foaf:Person ; foaf:name ?name .
  OPTIONAL { ?person foaf:mbox  ?email }
  OPTIONAL { ?person foaf:phone ?phone }
}
ORDER BY ?name LIMIT 100
#   OPTIONAL is a left outer join, as Cypher's OPTIONAL MATCH.

%%sparql
SELECT ?s ?externalLabel WHERE {
  ?s a foaf:Person ; ex:wikidataId ?wd .
  SERVICE <https://query.wikidata.org/sparql> {
    ?wd rdfs:label ?externalLabel .
    FILTER(lang(?externalLabel) = 'en')
  }
}
#   *** SERVICE queries a REMOTE ENDPOINT as part of your query. ***
#   Nothing in the property graph world does this, and for a genuine
#   data integration problem it is a decisive feature.
#   (It needs outbound network access from the cluster's VPC - which
#    is itself a design consideration.)

# ==================================================================
# *** HOW TO CHOOSE. In order. ***
# ==================================================================
#  1. ARE YOU INTEGRATING EXTERNAL, STANDARDS-BASED DATA, OR
#     PUBLISHING DATA FOR OTHERS TO INTEGRATE?
#       YES -> RDF. Global identifiers, standard vocabularies, and
#              SERVICE federation are what you are buying.
#       *** THIS QUESTION SETTLES MOST CASES. ***
#
#  2. DO YOUR RELATIONSHIPS CARRY DATA?
#       YES, and (1) was no -> PROPERTY GRAPH. Reification is a real
#       cost in triples, query complexity and speed.
#
#  3. DOES YOUR TEAM KNOW CYPHER?
#       YES -> openCypher on a property graph is the lowest-friction
#       choice, and the Neo4j course transfers almost entirely.
#
#  4. DO YOU NEED INFERENCE?
#       *** CHECK WHAT NEPTUNE ACTUALLY SUPPORTS BEFORE LETTING THIS
#       *** DECIDE ANYTHING. *** Neptune's inference support is
#       NARROWER than the RDF ecosystem implies. Test it:
%%sparql
INSERT DATA {
  ex:Employee rdfs:subClassOf foaf:Person .
  ex:p-0099 a ex:Employee .
}
%%sparql
SELECT ?p WHERE { ?p a foaf:Person }
#   *** DOES ex:p-0099 APPEAR? *** Run it. Record the answer. A
#   design that assumes RDFS or OWL reasoning and gets none is a
#   design that has to be rewritten, and the test takes two minutes.

# ==================================================================
# BULK LOAD FORMATS differ per model.
# ==================================================================
#   GREMLIN csv:
#     ~id,~label,name:String,email:String
#     ~id,~from,~to,~label,confidence:Double
#
#   openCYPHER csv:
#     :ID,:LABEL,name:String
#     :START_ID,:END_ID,:TYPE,confidence:Double
#
#   RDF:  ntriples | nquads | turtle | rdfxml
#     <http://example.test/p-0001> <http://xmlns.com/foaf/0.1/name>
#       "Ada Lovelace" .
#
#   "format": "csv" | "opencypher" | "ntriples" | "nquads" |
#             "turtle" | "rdfxml"
#
# Record the load times AND the resulting storage size for both
# models on the same domain. The RDF store is usually larger, and
# reification is why.

Discussion

No questions on this topic yet. Sign in to ask the first one.