Reference Fields and the Cost of Deeply Nested Content Graphs

References keep content normalized, but every level of indirection costs something at read time and in the editing interface. This post walks through when to link between schemas, when to embed data inline, and how to recognize the point where a content graph has become too deep to query comfortably.


Every content model eventually faces the same decision. You have an article, and the article has an author. Does the author live inside the article as a set of fields, or does the article point at a separate author entry?

The textbook answer is to normalize: one author record, referenced from many articles, edited in one place. That answer is correct often enough that it becomes a reflex. The problem is that it keeps being correct for the next decision, and the one after that, until you have an article that references an author who references an organization that references a location that references a country, and a single page render needs five round trips through the graph.

This post is about where that line sits and how to decide on purpose rather than by habit.

What a reference actually costs

A reference is a pointer. In a headless CMS the referenced item is a separate content entry with its own ID, its own status, its own versions and its own permissions. Nothing about it is free.

At read time, resolving a reference means the backing store has to fetch another document. One level is cheap. The cost becomes interesting when references fan out. An article with ten related products, each of which references a brand and three category entries, is not eleven lookups — it is forty-one, and the API has to assemble them before it can answer.

The second cost is less obvious: partial availability. A referenced entry can be unpublished, deleted or restricted while the referencing entry is live. Your frontend has to handle a reference that resolves to nothing. Embedded data cannot go missing on its own, because it has no independent life cycle.

The third cost is editorial. Every reference is a context switch. An editor working on a landing page who needs to fix a typo in a teaser has to figure out which other entry owns that text, open it, change it, and remember that the change lands everywhere else that teaser is used.

When embedding is the better answer

Embed when the data has no independent identity. A hero section with a headline, a subline and a background image is not a thing anyone will ever look up on its own, report on, or reuse across pages. Making it a separate entry buys you nothing and costs you a lookup and a context switch.

Most CMS products give you two embedding mechanisms. Arrays hold a repeating group of fields with a fixed shape. Components — called by various names across systems, in Squidex they are components and component lists — hold a structured block whose schema is defined once and can vary between entries, which is how page builders and flexible content sections are usually modelled.

The rule of thumb that holds up well in practice:

  • Embed if the data is owned by exactly one parent and dies with it.
  • Reference if the data is looked up by its own name, reused across parents, or edited by a different person than the parent.

Taxonomy, authors, products, locations and brands pass the second test. Layout blocks, bullet lists, call-out boxes and SEO overrides usually do not.

How each model reads back

The shape of your model shows up directly in the queries your frontend has to write.

Embedded data is already in the response. With GraphQL, a page with a component list is a single query with nested selection sets, and the server does not fetch anything extra:

{
  queryPageContents(filter: "data/slug/iv eq 'pricing'") {
    id
    data {
      title { iv }
      sections {
        iv {
          __typename
        }
      }
    }
  }
}

References in GraphQL are usually exposed as a resolvable field, so you can walk them in the same query. That reads well, which is exactly the trap: the query looks like one request, but the server still resolves every level. A three-level selection over a list of twenty items is a lot of work hidden behind tidy syntax.

REST with OData-style parameters makes the cost visible instead of hiding it. You filter, sort and page over one schema, and references come back as IDs:

GET /api/content/my-app/articles?$filter=data/category/iv eq 'guides'&$top=20

You then decide whether to make a second call for the referenced entries, batch them, or cache them separately. That is more code, but it is honest code — you can see how many requests you are making, and you can cache authors for an hour while articles stay fresh for a minute.

The filtering asymmetry matters more than the request count. Filtering on an embedded field is a query against the entry you are already selecting. Filtering on a field that lives behind a reference generally is not supported in the same expression, because the condition applies to a different document. If you need "all articles whose author works at a German organization", a deep reference chain will not give you that in one query. You will have to resolve top-down, or denormalize.

Denormalization as a deliberate choice

Denormalization has a bad reputation because it is usually accidental. Done on purpose, with a written reason, it is a reasonable engineering decision.

The common pattern is to keep the reference as the source of truth and copy the one or two fields you need to filter or display into the referencing entry. An article keeps a reference to the author and also stores the author's display name. Listings render without resolving anything; the detail page resolves the reference for the full profile.

The price is a sync problem. When the author's name changes, the copies are stale. You need an answer for that before you ship: a webhook or background job that rewrites affected entries, a scheduled reconciliation, or an explicit decision that staleness is acceptable because the copied field rarely changes. Most systems that can emit events on content changes — Squidex among them — give you a hook to drive that update. The mechanism is not the hard part. Deciding who owns the consistency guarantee is.

Write the trade-off down in the schema description. The next person to read the model needs to know that the duplicated field is intentional.

A depth budget

Set a limit before you start modelling, and treat crossing it as a design review rather than a refactor you will do later.

Two levels of reference from any entry a frontend fetches directly is a workable budget for most content sets. Three is manageable if the third level is small and cacheable, like a country list. Four usually means something in the middle should have been embedded, or that two schemas should be one.

When you hit the limit, the usual fixes are: embed the intermediate level into its parent, flatten by referencing the leaf directly from the top, or introduce a purpose-built entry that pre-assembles what a given surface needs.

Also budget breadth. Depth multiplied by list length is what actually hurts. A reference field that holds up to fifty items will dominate your response time long before a three-level chain of single references does.

Checking the model against the editor

A model that queries beautifully and edits badly will be worked around. Before you commit to a schema set, walk through the three or four most frequent editorial tasks and count the entries that have to be opened for each one. Publishing a news article should not require touching five records.

The inverse failure is just as real. If editors are copying the same paragraph into thirty entries, you embedded something that wanted to be a reference, and you will find out when the legal text changes.

If you are designing a schema set now, sketch the read queries for your three busiest pages before you create a single field. The query shape tells you more about whether the model is right than the entity diagram does.

The Squidex documentation covers references, components and the query syntax for both the GraphQL and REST endpoints, which is the place to look once you have decided what the model should be.