Nothing Is Updated: Designing an Append-Only Digital Twin
At Tesar, every fact about the physical world is a row that is never changed. A value moves for three different reasons, and an UPDATE erases which one it was. Three correction rules at read time decide what a default read returns, and the database's own privileges make sure nobody can quietly break the promise.
Rain fell on Tuesday over one stretch of a power corridor. By Friday, our system had given four different answers to the question "how much?", and every one of them was right when it was given.
On Monday evening a forecast said 12 mm. On Tuesday night a satellite product estimated 9 mm. On Wednesday morning the same provider restated it as 10 mm. On Thursday a rain gauge reported 11 mm.
If the table holding that number allows UPDATE, it ends the week holding 11, and the story of how it got there is gone. If an alert fired on Wednesday, nobody can show why. If an engineer asks what we believed on Tuesday night, we can only guess.
At Tesar, where I am CTO, we build a digital twin of physical infrastructure. One of its invariants is three words long: nothing is updated. This post is how that works, what it costs, and why I would make the same call again.
Short answer
Every fact the twin holds about the world is an Observation: a value for one variable, at one place, for one valid time, written by one run of one source, with the moment it became known. Rows are only ever appended. A value that changes is a new row, never an edit.
Since many rows can describe the same thing, three correction rules decide what a default read returns. A finished rerun hides the run it replaces. Within one producer, the newest known value wins. Across producers, measured data hides derived data, which hides simulated data. Because every row keeps its known time, any past answer can be read again, exactly, by asking "as of" that moment.
The database enforces it: the service's login can select and insert, and a test fails the build if it is ever granted more.
Key takeaways
- A value changes for three reasons: the world changed, the producer learned better, or a better producer arrived.
UPDATEcollapses all three into one. - Two time axes do most of the work: when a value was true (valid time) and when the system learned it (known time).
- Correction belongs to the read, not the write. Store everything; let a small set of rules choose.
- A rerun should hide what it replaces only once it has finished, or a half-written rerun blanks real data.
- "Never update" is a promise you can enforce with database privileges, not a code review habit.
- It costs read time, storage and a deletion story. We measured the first and planned for the other two.
Why an update is the wrong verb
In most products, an update is the honest verb. A user renames a project, and the old name is just wrong now.
Physical data does not behave like that. When the number for Tuesday's rain moves, it is one of three different events:
- The world changed. That is a new valid time, so it was never the same row to begin with.
- The producer learned better. A satellite provider reprocesses its data and restates the value. The old value was the best anyone had at the time.
- A better producer arrived. A gauge measured what the satellite only estimated.
Each event deserves its own row, because each answers a different question later. Why did a watch flag this corridor on Wednesday? Because the twin believed 10 mm on Wednesday. Was the model wrong, or the data it received? Compare the forecast row to the measured row. Did the provider's correction change anything we decided? Read the twin as of the hour before it arrived.
An UPDATE keeps the last answer and throws away the questions.
Two clocks on every row
Every Observation carries two times, and the design depends on keeping them apart.
Valid time is when the value was true in the world: rain on Tuesday. Known time is when the twin learned it: Monday evening for the forecast, Thursday for the gauge. The first comes from the producer. The second is set by the twin when the row is appended, and nobody can send a different one.
Illustrative values. Every answer in the strip can be read again later, exactly, by asking "as of" that moment.
Each row also carries its origin: measured for a sensor, derived for a value computed from measurements, such as a satellite rain product, and simulated for a model's estimate or forecast. Origin follows who produced the value, and the kind of source bounds it: a model cannot write a measured value.
The schema checks one rule of time directly. Only a simulated row may describe a moment that has not happened yet when it is written:
-- A sketch of the constraint, not the full table.
check (origin = 'simulated' or valid_from <= known_at)
A sensor cannot report tomorrow's rain. A forecast can.
Three correction rules, applied when you read
If every version is kept, something has to decide which one a normal read returns. In the twin that decision is made at read time by three rules, in this order.
1. A finished rerun hides the run it replaces. Producers rerun. A pipeline is fixed, a provider republishes a month, a model gets a better input. The rerun names the run it replaces, and from the moment it is recorded as finished, the old run's rows drop out of default reads.
The word "finished" carries real weight. Before it, the old run stays visible. A rerun that crashes halfway through hides nothing, so a failed backfill never blanks a month of real data. A rerun may also only replace a run of its own source, owner, origin and scenario. Anything else would let one producer hide data it never wrote, or let an estimate hide a measurement.
2. Within one producer, the newest known value wins. For the same variable, place and valid time, from the same source with the same parameters, the row with the latest known time is the current one. This is the provider restating Tuesday from 9 to 10 mm.
3. Across producers, the best origin wins. Measured hides derived, and derived hides simulated. Real data always hides an estimate. The estimate is still there, and it still matters: it is how we judge the model, and it is what the twin shows for the places no sensor covers.
In SQL, the shape is a distinct on for the second rule and a window function for the third, with the first as a filter before both:
-- A sketch of the shape, not the statement the twin runs.
with current as (
select distinct on (variable_id, place_id, valid_from, source_id, parameters)
o.*
from observation o join run r on r.id = o.run_id
where o.known_at <= :as_of -- read the past exactly
and not exists (select 1 from finished_rerun_of(r.id, :as_of)) -- rule 1
order by variable_id, place_id, valid_from, source_id, parameters,
known_at desc -- rule 2
)
select * from (
select c.*, min(origin) over (partition by variable_id, place_id, valid_from) as best
from current c
) ranked
where origin = best; -- rule 3
Two details make this more than bookkeeping. The known_at <= :as_of filter turns time travel into a parameter: the same statement answers "what do we believe now?" and "what did we believe at 23:00 on Tuesday?". And a caller can lift the rules entirely with a raw read, or by naming the runs it wants. Investigating a model, or a provider's correction, reads every row.
Scenarios ride on the same mechanism. A what-if run, such as "this corridor with 30% more rain", writes its rows under a scenario name. Default reads never see them, so a scenario can never leak into a real decision.
Making the promise enforceable
An invariant that lives in a design document lasts until the first urgent fix. So the promise lives in the database's privileges.
The store, the part of the twin that keeps Observations, connects through its own login. That login may select and insert in its schema. It may delete only from its outbox, the table of messages waiting to be published. It may not update anything. The few places where a narrow change is genuinely needed, such as claiming outbox rows or correcting a catalog entry, go through definer functions that do exactly one thing.
A test, run in CI against a real Postgres, tries the forbidden statements as that login and fails if any of them succeeds:
// A sketch of the test's shape.
assert!(as_store("update observation set value_number = 0").await.is_err());
assert!(as_store("delete from run").await.is_err());
assert!(as_store("delete from outbox").await.is_ok());
If someone ever grants the login more, the build fails. Nobody has to remember the rule during a review.
Deleting does exist, in exactly one case: when an owner's data must go, because a licence ends or a workspace leaves. That runs under a separate maintenance role, through its own path. The service that answers reads and writes cannot do it.
What it costs
This design is not free, and I would rather say so than pretend.
Reads do more work. Every default read applies the three rules. In an earlier post I measured it: reading one variable across the whole network took 0.3 s against the bare schema and about 2.4 s through the service with its rules on. Most reads are narrower and fast, but the widest is still the one we are working on. The rules cost something you can see.
Storage grows with every correction. Each restatement and rerun adds rows rather than replacing them. The table is partitioned by origin and by month, so old months are cheap to keep and cheap to skip, and the rows are small. For us it is a fair trade.
You cannot fix a wrong value in place. If a pipeline writes nonsense, the fix is a rerun that replaces it. That is slower than one UPDATE at two in the morning. It is also the only fix that leaves a record of what happened and why.
Not everything belongs here. Users, roles, workspaces and assets live in another service's database, with ordinary updates. A user who renames an asset just renamed it. Append-only is for facts about the world, where history is the product.
When I would not do this
If your data is user intent, such as settings, names and drafts, updates are correct and history is a feature you add when someone asks.
If nobody will ever ask "what did we know, and when?", the second clock is overhead. And if you cannot afford to apply rules at read time on your largest read, you will need materialized current views, which brings back some of the complexity this design avoids.
For a system whose job is to say what is happening to physical infrastructure, and to stand behind what it said yesterday, I do not see a better default.
The rule
Store every fact once, with when it was true and when you learned it. Let reads decide what is current.
Three words in our architecture document, "nothing is updated", turned out to shape the schema, the privileges, the tests, how reruns behave, and how we answer the hardest question a customer can ask: why did you tell me that?