Why is a GUID used as the type for the Id fields in the EventSources and Events tables in an EventStore database?

StackOverflow https://stackoverflow.com/questions/15914043

  •  03-04-2022
  •  | 
  •  

Pergunta

Why is uniqueidentifier (which equates to a GUID in .NET) used as the type for the Id fields in the EventSources and Events tables?

Would it not be faster to use an integer type (like bigint in SQL Server) that functioned as an identity, so that the database could assign the Id as the inserts are performed?

I am a complete newb when it comes to Event Sourcing and CQRS, so I apologize if this has been asked and answered and my searching hasn't been correct enough to find the answer.

Foi útil?

Solução

Note: Answers 2 and 4 assume that you are following a few basic principles of Domain-Driven Design.

  1. IDs should be unique across different aggregate types and even across different bounded contexts

  2. Every aggregate must always be in a valid state. Having a unique ID is part of that. This means you couldn't do anything with the aggregate before the initial event has been stored and the database generated and returned the respective ID.

  3. A client that sends the initial command often needs some kind of reference to relate the created aggregate to. How would the client know which ID has been assigned? Remember, commands are void, they don't return anything beyond ack/nack, not even an ID.

  4. A domain concern (identification of an entity) would heavily rely on technical implementation details (This should actually be #1)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top