Materialisation: rules of thumb - deliveroo/materialist GitHub Wiki

1. Keep materialisers as dumb as possible

  • Leave any logic out of your materialised entities (things like uniqueness and even required fields).
  • This is to avoid the logic on the resource owner side leaking into the consumer side.
  • If the resource owner changes mind about some decisions, your materialised world should not break.

2. Avoid ANY direct association between materialised entities

  • If A and B are associated in the resource owner, they should only be indirectly associated in the materialised world.
  • This is because of the eventual consistency. (At the time A record is created, the event for B may not have arrived yet)
class MicroContract
  # bad:
  has_one :slot

  # good:
  has_one :slot, foreign_key: :planning_id, primary_key: :planning_slot_id
end