Unlike relational databases, Cloud Datastore does not support SQL JOIN statements. If your application needs to fetch a user along with their organization details, you must run separate queries, which can double request latency. To optimize reads, NoSQL schema designs use Fast References and Denormalization.
By caching critical parent attributes directly inside child entities, you can resolve queries in a single read operation.
1. Denormalizing Entity Relationships
Instead of referencing parent IDs only, we duplicate name and status fields inside the child record, preventing the need for secondary lookups:
# Fast Reference modeling in Python NDB
from google.cloud import ndb
class UserOrganizationJoin(ndb.Model):
user_uid = ndb.IntegerProperty(required=True)
organization_uid = ndb.IntegerProperty(required=True)
# Denormalized fields to bypass joins during listing queries
organization_name = ndb.StringProperty()
organization_type = ndb.StringProperty()
2. Maintaining Consistency
To keep denormalized fields updated, the backend runs a background task queue job to sync name updates across child records whenever an organization's name is modified.