---
title: Relational data
description: How Avra RFM reads a relational database — its tables, the keys that link them, the names and values in its columns, and what each table's time means.
---

Avra RFM predicts over a relational database: the tables your systems already keep, linked by keys. You don't flatten them into one wide row first, and you don't build features. This page explains how the model reads that data, so you know what to send and why each part of it matters.

## Tables, rows, and keys

A relational database keeps each kind of thing in its own table, with one row per thing: a row for each customer, a row for each account, a row for each payment. Every row has an identifier of its own, its primary key, and rows point at each other by carrying those identifiers as foreign keys. A payment carries the ID of the account it came from, and the account carries the ID of the customer who owns it.

<svg class="fig" viewBox="0 0 640 376" role="img" aria-label="Three tables, customers, accounts, and payments, and the same rows drawn as a graph in which customers connect to their accounts, and accounts to their payments, through their keys">
  <defs>
    <marker id="fig-t2g-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse">
      <path d="M0,0 L10,5 L0,10 z" class="arrow" />
    </marker>
  </defs>
  <rect class="card" x="16" y="16" width="240" height="92" rx="6" />
  <rect class="head" x="16.5" y="16.5" width="239" height="24" rx="5.5" />
  <rect class="head" x="16.5" y="30" width="239" height="10.5" />
  <line class="rule" x1="16" y1="40.5" x2="256" y2="40.5" />
  <text class="title" x="28" y="33">customers</text>
  <text class="mono label" x="28" y="60">customer_id</text>
  <text class="mono label" x="132" y="60">since</text>
  <text class="mono" x="28" y="80">C1</text>
  <text class="mono" x="132" y="80">2021-03-14</text>
  <text class="mono" x="28" y="98">C2</text>
  <text class="mono" x="132" y="98">2023-11-02</text>
  <rect class="card" x="16" y="124" width="240" height="110" rx="6" />
  <rect class="head" x="16.5" y="124.5" width="239" height="24" rx="5.5" />
  <rect class="head" x="16.5" y="138" width="239" height="10.5" />
  <line class="rule" x1="16" y1="148.5" x2="256" y2="148.5" />
  <text class="title" x="28" y="141">accounts</text>
  <text class="mono label" x="28" y="168">account_id</text>
  <text class="mono label" x="132" y="168">customer_id</text>
  <text class="mono" x="28" y="188">A1</text>
  <text class="mono accent" x="132" y="188">C1</text>
  <text class="mono" x="28" y="206">A2</text>
  <text class="mono accent" x="132" y="206">C1</text>
  <text class="mono" x="28" y="224">A3</text>
  <text class="mono accent" x="132" y="224">C2</text>
  <rect class="card" x="16" y="250" width="240" height="110" rx="6" />
  <rect class="head" x="16.5" y="250.5" width="239" height="24" rx="5.5" />
  <rect class="head" x="16.5" y="264" width="239" height="10.5" />
  <line class="rule" x1="16" y1="274.5" x2="256" y2="274.5" />
  <text class="title" x="28" y="267">payments</text>
  <text class="mono label" x="28" y="294">payment_id</text>
  <text class="mono label" x="112" y="294">account_id</text>
  <text class="mono label" x="196" y="294">paid_at</text>
  <text class="mono" x="28" y="314">P1</text>
  <text class="mono accent" x="112" y="314">A1</text>
  <text class="mono" x="196" y="314">Apr 02</text>
  <text class="mono" x="28" y="332">P2</text>
  <text class="mono accent" x="112" y="332">A1</text>
  <text class="mono" x="196" y="332">May 02</text>
  <text class="mono" x="28" y="350">P3</text>
  <text class="mono accent" x="112" y="350">A3</text>
  <text class="mono" x="196" y="350">May 09</text>
  <line class="edge" x1="270" y1="196" x2="334" y2="196" marker-end="url(#fig-t2g-arrow)" />
  <text class="small label mid" x="302" y="186">keys</text>
  <line class="edge-accent" x1="380" y1="130" x2="480" y2="80" />
  <line class="edge-accent" x1="380" y1="130" x2="480" y2="180" />
  <line class="edge-accent" x1="380" y1="290" x2="480" y2="290" />
  <line class="edge-accent" x1="480" y1="80" x2="590" y2="50" />
  <line class="edge-accent" x1="480" y1="80" x2="590" y2="110" />
  <line class="edge-accent" x1="480" y1="290" x2="590" y2="290" />
  <circle class="solid" cx="380" cy="130" r="17" />
  <text class="mono mid on-solid" x="380" y="134">C1</text>
  <circle class="solid" cx="380" cy="290" r="17" />
  <text class="mono mid on-solid" x="380" y="294">C2</text>
  <circle class="soft" cx="480" cy="80" r="17" />
  <text class="mono mid" x="480" y="84">A1</text>
  <circle class="soft" cx="480" cy="180" r="17" />
  <text class="mono mid" x="480" y="184">A2</text>
  <circle class="soft" cx="480" cy="290" r="17" />
  <text class="mono mid" x="480" y="294">A3</text>
  <circle class="node" cx="590" cy="50" r="17" />
  <text class="mono mid" x="590" y="54">P1</text>
  <circle class="node" cx="590" cy="110" r="17" />
  <text class="mono mid" x="590" y="114">P2</text>
  <circle class="node" cx="590" cy="290" r="17" />
  <text class="mono mid" x="590" y="294">P3</text>
  <circle class="solid" cx="372" cy="350" r="6" />
  <text class="small label" x="384" y="354">customer</text>
  <circle class="soft" cx="458" cy="350" r="6" />
  <text class="small label" x="470" y="354">account</text>
  <circle class="node" cx="536" cy="350" r="6" />
  <text class="small label" x="548" y="354">payment</text>
</svg>

The same rows, as tables and as a graph. Every row becomes a node, and every key that points at another row becomes an edge.

## Your database is a graph

Follow the keys and the tables turn into a graph. Each row is a node, and each key that points at another row is an edge. In the figure, customer C1 connects to accounts A1 and A2, and account A1 connects to payments P1 and P2. Nothing in the data changed: the graph is another way of reading the same rows.

That way of reading matters because most questions about a record depend on what's connected to it. Whether customer C1 stops buying depends on its own payments, and also on the accounts they came from, the products in its orders, the tickets it opened, and how customers like it behaved. Following the edges from a record, one hop and then another, reaches everything related to it.

When the RFM makes a prediction about a record, it reads a sample of the rows connected to it this way, across the tables the keys reach, instead of a summary built in advance. That's why there's no feature table to build: the relationships stay in the data the model reads. See [How predictions work](/rfm/predictions).

## Keys

Keys turn separate tables into one database, so they're the part of your data that matters most. Each table that holds records needs a primary key, and every link needs a column whose values match the key it points at, written the same way in both tables. Identifiers can be legal documents, such as a CNPJ or a CPF, or your own keys.

The RFM learns the relationships from the keys, inferred from the data or declared when your pipeline is set up. A key written one way in one table and another way in the next, with and without punctuation, say, breaks the link, and the records on either side stop seeing each other. The ingestion pipeline's [checks](/data-ingestion/data-contracts) can catch that before it reaches a model: when your contract declares the relationship check, a key that doesn't resolve to a record blocks the run by default.

## Names, text, and values

The RFM reads table names, column names, and text values as language, Portuguese included. A column named `data_vencimento` or `valor_parcela` carries its meaning without being renamed, and free-text fields, such as a ticket's description or a transaction's memo, are read as text.

Numbers, booleans, timestamps, and text are each read as what they are. There's no encoding or scaling to do first, and a missing value is simply left out instead of being filled in.

## What a table's time means

Each table tells the model what its time means, and that choice decides what a prediction may see.

| Kind | The row's time is | Examples |
|------|-------------------|----------|
| **Static** | None: the row's values don't change | A product catalog, a list of branches |
| **Event** | When the event happened, which is also when it became known | Purchases, logins, payments recorded as they happen |
| **Available** | When the row became known, which can be later than the business event it describes | Records that arrive late, snapshots of a value that changes |

A payment made on September 5 that reaches your warehouse on September 9 wasn't known on September 7. A table whose rows can arrive late uses the time each row became known, and keeps the business date as an ordinary column that the model still reads. The [ingestion pipeline](/data-ingestion/time) keeps both times for every row, which is what makes that choice possible.

A row doesn't inherit its parent's time. Order lines with no time of their own would be visible before their orders, so give each line the time its order was placed, or the time the line arrived if that's later.

Each timed table also declares how far its data is complete. An outcome counted over a window that runs past the end of the data isn't the real outcome, so a target is computed only where every table it reads is complete through the end of its window.

## What makes good relational data

Send the records you want to score and every table that touches them, even indirectly: the counterparties on a transaction, the products on an order, the owners of a company. A relationship the model can't follow is signal it can't use.

Keep the keys consistent across tables, and give every timed table an honest time, when each row became known if that differs from when it happened. Send enough history to hold past outcomes for the periods you want to evaluate on, and send the outcomes themselves as data, each with its date. Your Avra team reviews all of this with you during data discovery. See [Preparing your data](/data-ingestion/preparing-data).

**[What you can predict](/rfm/what-you-can-predict)**

Frame a prediction: the records, the outcome, and the window

**[How predictions work](/rfm/predictions)**

What the model reads for each prediction, and what it never sees

**[Time and history](/data-ingestion/time)**

How the ingestion pipeline keeps when each row was true and recorded
