Able to append event to projection.

Hi,

I have created an aggregate stream ‘accounts’ by using a category projection over each ‘account-{id}’ stream.

fromCategory(‘account’)

.whenAny(function(s, e){

linkTo(‘accounts’, e);

});

``

This works nicely as I’m able to subscribe to the ‘accounts’ stream and create a specific read model for my use case. :slight_smile:

However, I was surprised to be able to append to the projection stream ‘accounts’ from the .net client.

I had assumed I would get a error.

Is this expected behaviour? If so can you explain how so, I imagine that it could have some powerful, but mind bending, use cases maybe?

Thanks

J

Yes, the stream that you are linking your events to is just a regular stream. You will see an error message like the one below if you stop/start the projection.

The reason for this is because when the projection writes the event (in this case a special event type is used “$>” called a link to event type), it also writes metadata with the event to identify the projection (and some other interesting information) that is writing to the accounts stream. There is a validation process that then takes place which will make sure that the projection that is about to write to the stream was the one that was previously writing to the stream. This is done by reading the last event in the stream and using it’s metadata to perform the above mentioned validation.

You will get

The accounts stream managed by projection {projection-id) has been written to from the outside.

"However, I was surprised to be able to append to the projection
stream 'accounts' from the .net client.
I had assumed I would get a error."

You will get an error from the projection saying something else wrote
to the stream.

There will be a setting you can enable (run with scissors mode) where
you could have a projection writing to a stream and other stuff
writing to the same stream.

btw you could just use the bycategory projection as its already doing
exactly what you are doing just to a different stream name $ce-account

Greg

Thanks for the prompt reply :slight_smile:

I stopped and re-started my projection, that I had appended directly to via the .net client, but didn’t receive or couldn’t see any error anywhere.

Thanks for the heads up in the $ce-{category} stream, very helpful.

J