Based on what this guy says: http://toddfredrich.com/ids-in-rest-api.html
Let assume he is right about using UUID to identify the api resources. Then I run into troubles trying to implementing it that way, this is:
class FooEntity {
final String id = null; //auto-generated by my backend (mongodb), not shared
final UUID uid = UUID.randomUUID(); //the resource id
}
(Between client and server, are sent and received DTOs, not data base entities.)
The problem now is that id
is not useful as I'm not using it anymore. The client makes the requests with uid
so why do I bother to handle 2 id's ?
Then we get back to the same issue of the beginning. If I set UUID as the primary key (_id
) then I'm exposing the backend id to the public.
Beside of that, there is the efficiency topic. I've read that indexing by ObjectId is much more efficient than UUID.