2021-03-28 07:42:51+00:00

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.

Denormalized Projection Properties vs. Batch Key Get (`ndb.get_multi`)

In non-relational Cloud Datastore / Firestore schemas, replace SQL JOIN queries with either denormalized summary fields updated asynchronously via task queues or parallel ndb.get_multi(keys) batch lookups backed by Memcache. See Freelance NoSQL Programmer Guide.


About the Author — Hire Freelance Programmer Aldian Fazrihady

Aldian Fazrihady is a Top-Rated Senior Freelance Programmer, Freelance Full Stack Developer, and AI Application Engineer with 15+ years of production software engineering experience and Google Cloud Professional Cloud Architect & Data Engineer certifications. He specializes in building custom LLM & autonomous AI agents, RAG pipelines, Next.js/React PWAs, Python (Django/FastAPI), Go microservices, and serverless cloud infrastructure on Google Cloud Run and AWS.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD via Polar) | View Live AI Portfolio | Portfolio Directory | Send a Direct Message

Related Engineering Articles

Freelance Programmer Specializations & Category Hubs