Learn Labs
3. Data Models and Query Languages

3.0 The layer stack

Most applications are built by layering one data model on another.

Most applications are built by layering one data model on another. For each layer the key question is: how is it represented in terms of the next-lower layer?

LayerWhat it isWhose problem
1 · Real worldApplication objects, data structures, APIs — people, organizations, goods, actions, money flows, sensorsApp developers
2 · General-purpose data modelJSON/XML documents · tables and rows · vertices and edges — this chapterApp developers
3 · BytesIn memory, on disk, on the network — queryable, searchable, manipulable representations (Ch 4)Database engineers
4 · PhysicsElectrical currents, pulses of light, magnetic fieldsHardware engineers

Each layer hides the complexity of the layers below by providing a clean data model. That's what lets database vendors' engineers and application developers work together effectively without knowing each other's internals.

Declarative query languages — the key terminology note

SQL, Cypher, SPARQL, and Datalog are declarative: you specify the pattern of the data you want — what conditions results must meet, how they should be transformed (sorted, grouped, aggregated) — but not how to achieve it. The query optimizer decides which indexes and join algorithms to use, and in which order.

With imperative languages (Python, Java) you write the algorithm: which operations, in which order.

Why declarative wins:

  1. More concise and easier to write than an explicit algorithm.
  2. More importantly, it hides implementation details of the query engine, so the database can introduce performance improvements without any changes to your queries.
  3. It enables automatic parallelism — the DB can execute the query across multiple CPU cores and machines without you implementing that. In a handcoded algorithm, implementing parallel execution yourself is a lot of work.

On this page