Rebuilding stream to 'insert' event

Hi,

Apologies if this has been asked/answered previously, but I wasn’t able to find it if it has been.

Basically I have a requirement to be able to retroactively ‘insert’ events under somewhat rare conditions by which I mean there will on occasion be events that were missed against an entity that need to be placed into the stream at the point they occurred rather than appended to the end of the stream.

The streams are partitioned and will rarely have more than a few hundred events in them, so I figured it wouldn’t be too bad to just take the stream the event belongs in and simply create a new stream the events up until the ‘new’ event happened, append the new event, and then stick the rest of the events from the ‘old’ stream on the end.

The thing I’m stuck with here is that I would essentially want the new stream to take the old stream’s place and pretty much hard delete the old stream, however I’m unsure of the best way to go about doing this, so I was hoping to get some pointers in case there was a simple way to go about this that I’m missing.

Cheers!

be explicit about it :

  • Append a “Correction” marker event at the end of the stream that needs to be rewritten.

  • read the stream

  • compute the full set of events as they should be and append them

  • eventually truncate the stream up to the “correction” marker event .

  • you’ll need to make sure all your consumer are idemptotent / take into account that correction & stream rewrite

Wow, this is so much more elegant than anything that crossed my mind.

Thank you very much Yves!

1 Like