Fork me on GitHub
#datomic
<
2018-11-22
>
tslocke09:11:56

Beginner question: is it idiomatic to work directly with numeric entity-ids, e.g. in a URL like /user/:id? I've seen example code where an attribute like :user/id is used, but I'm not sure what the advantage of using such an attribute would be over the entity-id.

val_waeselynck10:11:51

Strongly not recommended to expose entity ids externally (especially in a durable way).

val_waeselynck10:11:14

There are various reasons in the evolution of your database which may cause you to renumber your entities, so don't rely on entity ids being stable.

tslocke10:11:58

Thanks v much for the help. So, If I'm going to create e.g. :user/id, is there any support for generating those IDs?

val_waeselynck10:11:36

You could use UUIDs, or if that's not suitable use or take inspiration from https://github.com/vvvvalvalval/datofu#generating-unique-readable-ids

tslocke10:11:16

UUID seems like overkill for something that only needs to be unique within this database

val_waeselynck10:11:27

Overkill in what sense? UUIDs are essentially the least thought-consuming id generation strategy, it's the last thing I'd call overkill 🙂

tslocke11:11:41

I guess I meant unnecessarily large, but I take your point.

val_waeselynck14:11:15

Oh I see. Well, 128 bits of entropy, could be worse. I think Datomic has efficient storage and memory layouts for it. You could also represent it in text by encoding it in base64, this way you can represent it with 22-chars Strings, not that bad.

Dustin Getz14:11:01

You can find much shorter for not-quite-uuids

tslocke16:11:17

@U09K620SG thanks for the pointer. However: > Many UUID generators produce data that is particularly difficult to index, which can cause performance issues creating indexes. To address this, Datomic includes a semi-sequential UUID generator (https://docs.datomic.com/on-prem/identity.html) I think I'll just accept the long URLs 🙂

Dustin Getz16:11:52

Is squuid still a thing? I thought Datomic has since solved this with adaptive indexing

tslocke16:11:53

Hmm that could well be true. I have no idea

tslocke16:11:24

Found something similar at the same time. Thanks