Order of events linked to stream from custom projection

When EventStore is partitioned over multiple nodes

and I create projection that links event to another stream:

fromAll(

.when(

``
MyEventType: function(state, event){ linkTo('MyViewStream') }) );

``


How are the events ordered in the MyViewStream?

I mean the events can come from different partitions with some drift in system time, so I wonder what will be the order or the events when I read the events from the stream.

Is it based on timestamp, or first come, first serves principle?

In case the timestamp is different from the order as they were linked to the stream, it there a guarantee that ReadEventsFromStream will return events always in the same order?

ReadEventsFromStream will always return the same order.

How are you getting different orders? Are you using multiple nodes and some custom way of synchronizing events?

No, I’m just curious how the synchronization of events works, because timestamp is not reliable in distribuded event store. But I think I’m getting the idea. linkTo(’‘MyViewStream’) physically writes the events to MyViewStream on a single node, where it is synchronized on first come first serve principle.

It’s all ordered by the Position of the event: https://github.com/EventStore/EventStore/blob/master/src/EventStore.ClientAPI/Position.cs

Close:

linkTo(…)

actually writes a special event which is known as a link event. Because its an event it is ordered. Upon read a linkTo event acts as a pointer and if requested will result in following the pointer (there is a bool flag for whether or not to follow the link). Does that make sense?

Yes, perfect sense. One additional question: is linkto synchronous with the SaveEvent operation?

I mean, can I retrieve the linked event from the second stream immediately after the original event is saved, or is it delayed?

I am not sure I understand the question.

await AppendToStreamAsync(‘stream1’, ExpectedVersion.Any, myEvent);
var events = await ReadStreamEventsForwardAsync(‘MyViewStream’, start, int.Max, true);

``

at the time I call ReadStreamEventsForwardAsync(‘linked-stream’), is there a guarantee that myEvent is already in linked-stream? if the linkTo is asynchronous, I can’t expect this method call to return myEvent, can I?

No you cant but this has nothing to do with EventStore this is just how async calls work. The operations will be ordered so that on the connection the write happens before the read but the write may not have finished before the read occurs.