Duplicate events depending on EventID

Hi Guys,

Could someone help me understand why this is happening?

When I post the example from http://docs.geteventstore.com/introduction multiple times I get only one entry in the stream as expected, However if I change the guid to something I generated I get a new event every time I insert the same event.

[
  {
    "eventId": "**13acffdd-73dc-1014-b57c-dfdd7340af8a**",
    "eventType": "event-type",
    "data": {

      "a": "1"
    }
  }
]

Maybe you can post an example session with curl?

So I ran the curl command twice for the same event and I get 2 entries.

C:\Users\colin>curl -i -d @event.txthttp://10.116.1.17:2113/streams/newstream” -H “Content-Type:application/vnd.eventstore.events+json”

HTTP/1.1 201 Created

Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS

Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-Forwarded-Host, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVersion, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion

Access-Control-Allow-Origin: *

Access-Control-Expose-Headers: Location, ES-Position

Location: http://10.116.1.17:2113/streams/newstream/27

Content-Type: text/plain; charset=utf-8

Server: Mono-HTTPAPI/1.0

and if you set expectedversion header to say 29 and do twice?

Cant say i have used Expectedversion before but here it goes :-> With a value of 29 is comes back with HTTP/1.1 400 Wrong expected EventNumber while with 28 it seems to create event 29… is this expected?

C:\Users\colin>curl -i -d @event.txthttp://10.116.1.17:2113/streams/newstream” -H “Content-Type:application/vnd.eventstore.events+json” -H “ES-ExpectedVersion:29

HTTP/1.1 400 Wrong expected EventNumber

Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS

Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-Forwarded-Host, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVersion, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion

Access-Control-Allow-Origin: *

Access-Control-Expose-Headers: Location, ES-Position

Content-Type: text/plain; charset=utf-8

Server: Mono-HTTPAPI/1.0

You have to run the same expected version multiple times with the same
data (and the correct expected version based on the stream). Expected
version basically states what version you expect the event to be (eg
concurrency control)

Is this post an idempotency problem with the list?

So currently I am at event 29 and I ran the command multiple times using an expected version of 30. keep getting 400 Wrong expected EventNumber

C:\Users\colin>curl -i -d @event.txthttp://10.116.1.17:2113/streams/newstream” -H “Content-Type:application/vnd.eventstore.events+json” -H “ES-ExpectedVersion:30”

HTTP/1.1 400 Wrong expected EventNumber

Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS

Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-Forwarded-Host, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVersion, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion

Access-Control-Allow-Origin: *

Access-Control-Expose-Headers: Location, ES-Position

Content-Type: text/plain; charset=utf-8

Server: Mono-HTTPAPI/1.0

Did you try 29?

trying 29 added event 30

Well at this point it seems to be, to clarify my understanding:

  • If I insert an event with the same EventID multiple times it should only insert once.
  • All event ids are GUIDs and are treated the same
  • Expected version is used to support concurrent writing to multiple streams with the same event ID
    It this right? If so I would expect if my stream has 30 events and I try to submit the last event again with expectedversion of 30 I should get a response 201 created but location of 30 as it is a duplicate of the last event.

The rules for idempotency are in the documentation but they are:

Idempotency is for retrying operations.
When retried and expected version is used idempotency is 100%
When retried without expected version idempotency is "best attempt"

Should how I generate the GUID have any baring on the duplicate events? When I use the GUID in the example it works as expected. (no duplicate insertions) But when I use the GUID I generate duplicates!

~  cat data.json
[
  {
    "eventId": "13acffdd-73dc-1014-b57c-dfdd7340af8a",
    "eventType": "event-type",
    "data": {

      "a": "1"
    }
  }
]
~  curl -i -d @data.json "http://localhost:2113/streams/newstream"
-H "Content-Type:application/vnd.eventstore.events+json"
HTTP/1.1 201 Created
Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type, X-Requested-With,
X-Forwarded-Host, X-PINGOTHER, Authorization, ES-LongPoll,
ES-ExpectedVersion, ES-EventId, ES-EventType, ES-RequiresMaster,
ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ES-Position
Location: http://localhost:2113/streams/newstream/0
Content-Type: text/plain; charset=utf-8
Server: Mono-HTTPAPI/1.0
Content-Length: 0
Keep-Alive: timeout=15,max=100

~  cat data.json
[
  {
    "eventId": "13acffdd-73dc-1014-b57c-dfdd7340af8a",
    "eventType": "event-type",
    "data": {

      "a": "1"
    }
  }
]
~  curl -i -d @data.json "http://localhost:2113/streams/newstream"
-H "Content-Type:application/vnd.eventstore.events+json"
HTTP/1.1 201 Created
Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS
Access-Control-Allow-Headers: Content-Type, X-Requested-With,
X-Forwarded-Host, X-PINGOTHER, Authorization, ES-LongPoll,
ES-ExpectedVersion, ES-EventId, ES-EventType, ES-RequiresMaster,
ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Location, ES-Position
Location: http://localhost:2113/streams/newstream/0
Content-Type: text/plain; charset=utf-8
Server: Mono-HTTPAPI/1.0
Content-Length: 0
Keep-Alive: timeout=15,max=100

~ 

This is so odd. it is adding for me… I think I will dump the container and try again.

C:\Users\colin>type event.txt

[

{

“eventId”: “13acffdd-73dc-1014-b57c-dfdd7340af8a”,

“eventType”: “event-type”,

“data”: {

“a”: “1”

}

}

]

C:\Users\colin>curl -i -d @event.txthttp://10.116.1.17:2113/streams/newstream” -H “Content-Type:application/vnd.eventstore.events+json”

HTTP/1.1 201 Created

Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS

Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-Forwarded-Host, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVersion, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion

Access-Control-Allow-Origin: *

Access-Control-Expose-Headers: Location, ES-Position

Location: http://10.116.1.17:2113/streams/newstream/30

Content-Type: text/plain; charset=utf-8

Server: Mono-HTTPAPI/1.0

SO I dumped the container and it is not inserting duplicates anymore…

I will see if i can get the store back into that state and create a reproducible test case.

Thanks so much for your help Greg.