Data Merging

Hi All,

I have a situation where in one user make changes to one property of stream and other user changes other property of the same stream but when user hit save button the last user’s change is saved not for the first…

How can I make changes merge for both the user in ES?

Any help will be great

What do you mean "one property of a stream"?

User A creates an event

{
  "EventSourcedId": "9c296e27-1fb5-4f4b-9435-36a9e21db2e8",
  "ActivityId": "fc76f130-bbb1-4b11-85c4-399da9f26885",
  "Activity": {
    "id": "fc76f130-bbb1-4b11-85c4-399da9f26885",
    "type": "productmovement",
    "time": 1445268714,
    "data": {
      "oratktnumber": null,
      "dtnumber": null,
      "origin": null,
      "receivedon": null,
      "destination": null,
      "isoratkt": false,
      "lineitems": [],
      "wholemudtank": [],
      "wholemud": []
    },
    "createdby": "User A"
  },
  "When": "2015-10-19T15:31:54.0181075Z"
}

event has ActivityId which is appended to the index activity

{
  "EventSourcedId": "9c296e27-1fb5-4f4b-9435-36a9e21db2e8",
  "Index": [
    "36f3cbaf-1d8a-4498-a8d4-d90513475fe8",
    "29f0bb17-2e58-422d-a772-2268be27fd06",
    "5d76a006-83d1-449e-8bbe-5db671452cb7",
    "fc76f130-bbb1-4b11-85c4-399da9f26885" (Index added)
  ],
  "When": "2015-10-19T15:31:54.0241075Z"
}

User B creates an event

{
  "EventSourcedId": "9c296e27-1fb5-4f4b-9435-36a9e21db2e8",
  "ActivityId": "FB75AEE1-348C-447B-9A46-4430896F387A",
  "Activity": {
    "id": "FB75AEE1-348C-447B-9A46-4430896F387A",
    "type": "productmovement",
    "time": 1445268714,
    "data": {
      "oratktnumber": 123456,
      "dtnumber": null,
      "origin": US,
      "receivedon": null,
      "destination": null,
      "isoratkt": false,
      "lineitems": [],
      "wholemudtank": [],
      "wholemud": []
    },
    "createdby": "User B"
  },
  "When": "2015-10-19T15:31:54.0181075Z"
}

but when User B saves his data the Index of User A is overwritten or removed though ES has that data(loses User A Index)
{
  "EventSourcedId": "9c296e27-1fb5-4f4b-9435-36a9e21db2e8",
  "Index": [
    "36f3cbaf-1d8a-4498-a8d4-d90513475fe8",
    "29f0bb17-2e58-422d-a772-2268be27fd06",
    "5d76a006-83d1-449e-8bbe-5db671452cb7",
    "FB75AEE1-348C-447B-9A46-4430896F387A" (Index added)
  ],
  "When": "2015-10-19T15:31:54.0241075Z"
}

After merging THE RESULT SHOULD be :

{
  "EventSourcedId": "9c296e27-1fb5-4f4b-9435-36a9e21db2e8",
  "Index": [
    "36f3cbaf-1d8a-4498-a8d4-d90513475fe8",
    "29f0bb17-2e58-422d-a772-2268be27fd06",
    "5d76a006-83d1-449e-8bbe-5db671452cb7",
    "fc76f130-bbb1-4b11-85c4-399da9f26885",
    "FB75AEE1-348C-447B-9A46-4430896F387A"
  ],
  "When": "2015-10-19T15:31:54.0241075Z"
}

which is not happening.

How Can I merge.

I am new to use Event store.

Regards

Himanshu Chandra

it will be fine if you have any video session shared regarding this

We know nothing of your events how would you expect us to merge it? We
only see them as byte []

You have to listen to the eventstream and merge them yourself. with a third event. Or use optimistic locking and discard the last one.

You can determine the conflict by setting "expected version" on both
writers. One will win the other will get a concurrency exception (you
can then re-read and merge if you like).