Firestore Unique ID's Generates By The Machine Or On The Backend When Using Set?

- 1 answer

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?



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.