Entity / Laws

Failure and recovery

  • Pre-existing broken rows: Invariants check writes, not existing tables. An update on a broken row succeeds only if the resulting row satisfies every invariant.
  • Missing fields on the client: Missing fields produce Undecided rather than Valid; the client sends the write and lets the server decide.
  • Adding a strict document law to live data: Because laws evaluate strictly on the resulting snapshot, you can ease live documents toward a cap using a monotone law:
    ts
    const Shrinking = forApplication(BoardApp).make({
      documentId: DocumentId.make('shrinking-board'),
      shared: Projection.pick(BoardApp.model.todos),
      durable: MessageSet.make(BoardApp, [BoardMessage.CreatedTodo]),
      laws: {
        atMost100Todos: {
          holds: ({ before, after }) =>
            after.todos.length <= Math.max(100, before.todos.length),
          message: 'A board holds 100 todos',
          path: ['todos'],
        },
      },
    })
    Before deploying a strict law, scan existing snapshots with Board.judge(snapshot, snapshot).
  • Lost mutation response: Retries carry the same operation ID; see Declared writes for retry guarantees.