To clarify: the microservice
term doesn't mean anything particularly special in GAE with respect to Datastore interaction (or otherwise) - all GAE services/modules are equals from this perspective. What makes a GAE service/module a microservice
is simply the functionality it performs, not its implementation or how it uses the infrastructure, see Microservices Architecture on Google App Engine.
All services of the same GAE project/application that access the datastore using the ndb
library can do that by default, without any restriction or additional service configurations.
The only trick is that all services referencing a particular entity type must have a consistent view of that entity's model definition. This is a requirement coming from the particular implementation of the ndb
client library, not from the datastore itself.
The simplest way to obtain such consistent view is IMHO by sharing the same ndb
model definition source file(s), which can be achieved by symlinking the same actual source file(s) (or the directories holding them) across the multiple service/module directories, as described in Sharing entities between App Engine modules.
In other words all your services/modules needing to query/access/reference Users
entities one way or the other would actually have the same Users
model definition available to do so.
Care must be exercised when deploying changes to the model definitions (be it in different services or even between different versions of the same service) either by:
- ensuring backward-compatibility with migration strategies
- proper deployment orchestration - i.e. ensuring incompatible versions/services never run simultaneously
The same technique can be used for memcache, in a similar manner: a shared source code file would export the definitions of memcache keys for the memcached values that need to be shared across services. Or, better yet, provide actual read/write functions for the corresponding data, to ensure not only that the data is stored under the right keys, but it also has the matching format.
With such shared code in place the memcached data representing certain pieces of information becomes shared across the same app's services/modules (again, regardless of them being microservices or not). Almost as good as the info shared via the datastore, except without transaction support to guarantee consistency.