Skip to content

CHR0012: Event types should avoid nullable properties

Event types can contain nullable properties, but this is often an anti-pattern in event sourcing. A nullable field can hide multiple meanings in one event. Prefer expressing optional facts with a dedicated event type when possible.

Warning

using Cratis.Chronicle.Events;
[EventType]
public record MissionAccepted(
string MissionId,
DateOnly? StartDate);
using Cratis.Chronicle.Events;
[EventType]
public record MissionAccepted(
string MissionId,
DateOnly StartDate);
[EventType]
public record MissionAcceptedWithoutStartDate(
string MissionId);

Events represent immutable facts. Nullable properties can blur the meaning of those facts and force consumers to branch on missing values.

Keeping event types explicit:

  • improves readability
  • reduces ambiguity for projections, reducers, and reactors
  • keeps event history easier to understand
  • CHR0001: Event sequence append operations