An Order That Remembers the Customer as They Were¶
A customer ordered a jacket in March and had it sent to their flat in Berlin. In June they moved to Munich and updated their address. In July they ask for a copy of the March invoice, and your system prints Munich. Or worse: the returns team ships a replacement to the wrong city.
The bug is a reference without a version. The order points to "the customer", and the customer has changed.
Copy, or point?¶
There are two common fixes, both with a cost.
- Copy the customer's name and address into the order. The order is now right forever, but the data exists twice, and copies are what make GDPR erasure hard: every copy has to be found.
- Point to the customer and keep an audit table of every change. Nothing is copied, but answering "what did this look like in March?" is a reconstruction.
ObjectsGrid does a third thing: it points to the customer at a version.
Every write is a version¶
Every write to an object keeps the previous version, and any of them can be read:
curl "https://apis.objectsgrid.com/persons/<id>?version=1763025002419837" \
-H 'X-ObjectsGrid-AccessPoint: EU' \
-H "Authorization: Bearer $TOKEN"
A version is the object's meta.objectVersion, also sent as its ETag. Earlier versions stay readable after the
object is deleted, so a record pointing to one never breaks. A version the object never had is 404.
Pinned references¶
Some references are about the thing as it was. ObjectsGrid pins them itself: when you write an Order with a customer,
it stores the version that was newest at that moment:
"customer": {"at_id": "https://apis.objectsgrid.com/persons/<id>?version=1763025002419837", "id": "<id>", "at_type": "Person"}
The same holds for an Invoice's customer, the agent of a
return and of a payment. A
checkout pins each accepted Offer the same way, so the order keeps the
price the shopper saw. Reading the order with GraphQL resolves the customer at that version, in the same request:
query {
order(id: "<order>") {
orderDate
customer { ... on Person { givenName familyName address { addressLocality } } }
}
}
The March order says Berlin, the customer's profile says Munich, and both are right.
Finding records by what they point to¶
A pinned reference still finds its records. A where on it matches the at_id without the version, so all of a
customer's orders are one list, whatever version each points to:
curl -G https://apis.objectsgrid.com/orders \
-H 'X-ObjectsGrid-AccessPoint: EU' -H "Authorization: Bearer $TOKEN" \
--data-urlencode 'where={"customer": {"at_id": {"equals": "https://apis.objectsgrid.com/persons/<id>"}}}'
Versions and personal data¶
Pinning keeps old versions alive, and old versions of a Person hold personal data. So erasure has to reach them, and it does: a Person's personal fields are encrypted per person, and an erasure deletes the keys, so every version becomes unreadable at once. The versions orders point to are kept for accounting, readable only by accounts tagged for it, for as many years as your Organization Account's retention says. See GDPR right to erasure without breaking your data.
Versions you can use¶
Versions aren't only for orders. They let you:
- roll back a bad change, by reading the version before it and writing it back;
- show what changed after an optimistic concurrency conflict;
- answer "what did it say then?", for a price, a return policy or a configuration.
An earlier version carries the object's current tags, so your access policy decides on today's tags, not on the ones it had then. The REST API guide has the details.