homerun
homerun

Reputation: 20765

Firestore Unique ID's generates by the machine or on the backend when using Set?

I need to know whether the unique id's generated by the Firestore is generated locally or on the backend? I can guess it's being generated locally because the following example

DocumentReference ref = db.collection("collection_name").document();
String id = ref.getId();

Or am I wrong and the create of the reference actually calling the server to allocate space and generate an ID?

Upvotes: 1

Views: 187

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599551

The auto-IDs generated by Firestore are generated in your client-side code. This is actually quite important, because that means they'll also work when your Android device doesn't have a connection to the server.

There is no concept of reserving blocks of IDs. Instead uniqueness is ensured by having enough entropy in the ID. Essentially: it's a sufficiently long and random that chances of two clients generating the same ID are incredibly small.

Upvotes: 2

Related Questions