pythongoogle-app-enginegoogle-cloud-datastoreapp-engine-ndb

Google Cloud NDB integer vs urlsafe IDs?


The google-cloud-ndb Python library provides two ways of generating identifiers for Datastore entities:

If I am creating a URL mapping to a specific entity (eg: /users/<user_id>/) can I use either of these ID options?

I assume there is some benefit to using the base64 encoded version for URLs? The only issue is it results in some pretty ugly URLs, so I prefer to use the integer for aesthetics.

Is there a technical benefit (like improved performance) to using either option?


Solution

  • the urlsafe keys are useful if you specify your own custom ids when creating entities, since your custom id may include characters that cannot go in a url.

    Also the urlsafe key has the kind and project id baked into it, which can be handy in case you get some wires crossed and pass the wrong id to the wrong spot.

    I wouldn't say there is a performance benefit.

    Another note about the urlsafe keys is that the format did change recently. The ndb library is backwards compatible, so in general it should've been fine, but that's something that they could possibly do again in the future, so just be aware of that.