Generating unique IDs?

820 views
Skip to first unread message

Olivier Lalonde

unread,
May 15, 2016, 12:32:23 AM5/15/16
to DDD/CQRS
In a traditional CRUD web apps, IDs are typically left to the database (serial in Postgresql, auto increment in MySQL, etc.)

How do event sourced systems typically generate unique IDs for objects? UUIDs? Stripe generates interesting IDs and seems to be using an event sourced system internally: ch_18BGtA2eZvKYlo2CBnU9wr29 (https://stripe.com/docs/api#charges). Does anyone know how this style of ID is generated without synchronisation through a SQL database? 

Thanks,
Oli

Greg Young

unread,
May 15, 2016, 7:04:29 AM5/15/16
to ddd...@googlegroups.com
There are lots of ways of generating ids. uuids are one common way.
Another to look at is similar to a high low strategy. Also see
snowflake. It depends what features you need of an id.
> --
> You received this message because you are subscribed to the Google Groups
> "DDD/CQRS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dddcqrs+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Studying for the Turing test

Yurii Rashkovskii

unread,
May 16, 2016, 1:28:02 AM5/16/16
to DDD/CQRS
Hi Olivier,

Personally, I use random UUIDs for unique identification and Hybrid Logical Clock timestamps when I need to establish ordering and causality between entities.

--

Ben Kloosterman

unread,
May 16, 2016, 6:12:56 AM5/16/16
to ddd...@googlegroups.com
On Sun, May 15, 2016 at 2:32 PM, Olivier Lalonde <olal...@gmail.com> wrote:
In a traditional CRUD web apps, IDs are typically left to the database (serial in Postgresql, auto increment in MySQL, etc.)

I would not say this is traditional  , compound/ natural  keys can be common and if data is created in multiple places even with CRUD Guids are used. 

How do event sourced systems typically generate unique IDs for objects? UUIDs? Stripe generates interesting IDs and seems to be using an event sourced system internally: ch_18BGtA2eZvKYlo2CBnU9wr29 (https://stripe.com/docs/api#charges). Does anyone know how this style of ID is generated without synchronisation through a SQL database? 

Guid.NewGuid().. a lot of pain and round trips avoided at a mostly acceptable cost to index size. 

If your storing in a SQL system you  need another field for your cluster or use a lib to create sequential guid.   For distributed system you cant use sequential Guids so you need another field.

Just like a single db , if you have a single service which wraps your data you can just use an incrementing static number ( with cmp/exchange)  which is loaded from the max value at startup.  

Ben

Oğuzhan Eren

unread,
May 25, 2016, 6:07:16 AM5/25/16
to DDD/CQRS
You can generate long number using things like timestamp+machine id + sequential number 





16 Mayıs 2016 Pazartesi 13:12:56 UTC+3 tarihinde Ben Kloosterman yazdı:
Reply all
Reply to author
Forward
0 new messages