0

It's best practice to randomise document ids to avoid hotspots in Firebase Firestore. How random does an id need to be to be 'not sequential'?

For example, a bad pattern is Customer1, Customer2, Customer3 because it is sequential. Would it be okay to have ACustomer1, aCustomer2, KCustomer3. ie, what would it take to break the sequentiality; is adding a random letter at the start enough?

Let's take some ids in a collection:

  • 123A47652hAShd
  • 123A4asdqwafAa
  • 123A4ad32a2da2f3

All of the records start 123A<FIRESTORE_RANDOM_ID>. Is it fine that the ids start the same, if there is a good amount of variability overall?

I want to export some Stripe records to firestore, all of which start txn_1234123... and for idempotency and consistency I want to use the same ids in firestore. Will it lead to hotspots since all the records in the collection start with the same 10 characters?

The new Key Visualiser for Firestore is a great way to check for hotspots and analyse Firestore usage patterns on existing data. But I'm trying to get a solid design up front, thanks everyone.

digibake
  • 448
  • 4
  • 12
  • can you refer to this link : https://stackoverflow.com/a/53901549/15774176 is it helpful? – Divyani Yadav Mar 02 '22 at 13:07
  • Yes, thanks that is helpful. That answer says firestore "will split the range being served by it and assign it to 2 machines." but it doesn't mention how it does the split – digibake Mar 02 '22 at 14:29
  • you can refer to this link : https://groups.google.com/g/google-cloud-firestore-discuss/c/_vJorp7yS1E Is it helpful? – Divyani Yadav Mar 03 '22 at 12:03

0 Answers0