0

Can we assume anything about them? Are they globally unique (across all of Firebase)? Is there any sort of ordering? Does the client matter?

Is there a public library / documentation so I can generate those IDs as well?

I am referring to the ones generated by push

Shamoon
  • 41,293
  • 91
  • 306
  • 570
  • What type of ID are you talking about? The ones from `push()`? Those are documented here: https://www.firebase.com/blog/2015-02-11-firebase-unique-identifiers.html – Frank van Puffelen Dec 18 '15 at 17:54

1 Answers1

5

There is a blog post on it, as well as a Gist.

From the blog post, here's the core of What's in a Push Id:

A push ID contains 120 bits of information. The first 48 bits are a timestamp, which both reduces the chance of collision and allows consecutively created push IDs to sort chronologically. The timestamp is followed by 72 bits of randomness, which ensures that even two people creating push IDs at the exact same millisecond are extremely unlikely to generate identical IDs. One caveat to the randomness is that in order to preserve chronological ordering if a client creates multiple push IDs in the same millisecond, we just ‘increment’ the random bits by one.

To turn our 120 bits of information (timestamp + randomness) into an ID that can be used as a Firebase key, we basically base64 encode it into ASCII characters, but we use a modified base64 alphabet that ensures the IDs will still sort correctly when ordered lexicographically (since Firebase keys are ordered lexicographically).

Also something amazing to note, is the ports for several different languages, done by the community:

So perhaps the best way to learn is pick a language not on that list and port it!

David East
  • 31,526
  • 6
  • 67
  • 82
  • Hi David, I would like to mention, Java's port doesn't work as original gist. The last timestamp value is inside the method itself so it will always be false while matching with the previous timestamp in that case. – kirtan403 Jul 29 '16 at 05:19