xybrek xybrek - 2 months ago 15
Java Question

GAE Long ID's too long is there a way to get shorter Long ID's?

During localhost development the ID's generated by GAE, starts with 1.

However in a real GAE deployment in the cloud, the ID generated even for the firsts entities are quite long like,

, is there a work around to make the first entities to start with 1, 2, 3.. and so on?

One might suggest to use Sharded Counters, and yes I've used this, however some suggests that sharded counters are not to be used as app might get the same count as it is eventually consistent.

In this case what could be the best solution?


The official post explaining the switch from sequential to 'scattered' ids is here.

The instructions for reverting to sequential behaviour are here, but note the warning that this option will eventually be removed.

The 'best' solution depends on what you need and why. You'll get better datastore performance with scattered ids, but honestly, you might not notice much difference if your app makes gets a small number of requests and makes light use of the datastore. If that's the case, you can use roll your own sequential ids based on a simple entity with a property that holds the the current high watermark id, and rely on having a low transaction rate to keep you from running into limits on the number of transactions per entity.

Reliably handing out sequential ids without gaps in a distributed systems is challenging.