First we define a class for the unique index counter like SEQUENCE in Oracle.
nextval = db.IntegerProperty(default=0)
Then, we define a kind that makes use of this sequence.
index = db.IntegerProperty(required=True)
name = db.StringProperty()
When a new entity of Entry is created, it must be added to the Sequence entity group, and the index must be the incremented nextval of the Sequence entity. This value will then be used to label the index of the new Entry element. We can put these two operations into a transaction.
s = Sequence.get(seqkey)
s.nextval += 1
entry = Entry(parent=Sequence, index=s.nextval)
seqkey = 'my_egroup_key'
Entity groups should not be too large so that the whole lot can be distributed evenly. A single sequence counter will become the bottleneck in this respect. It is better that the Sequence entities be separated into multiple groups by some kind of boundary and the Entry entities follow these sequence entities. This requires careful design of the data model.