Replicating Cloud Datastore to Firebase Realtime Database on App Engine
2020-04-14 16:51:25+00:00
Cloud Datastore is a robust, auto-scaling NoSQL database for server side operations. However, it lacks native support for pushing real-time updates to web browsers. If your application needs to show live dashboards or telemetry status feeds, clients must poll the database continuously, causing high read costs. A clean solution replicates updates from Datastore to the Firebase Realtime Database asynchronously, which then pushes changes to active clients.
By using Google App Engine Task Queues, we can capture Datastore modifications and mirror key-value states to Firebase.
1. Enqueuing Replication Tasks
Whenever a telemetry entity is updated in Datastore, the backend enqueues a background task containing the record data to be synced:
# db_replicator.py
from google.appengine.api import taskqueue
import json
def save_entity_and_sync(entity):
# Save to main Cloud Datastore
entity.put()
# Enqueue replication task
payload = {
"device_id": entity.device_id,
"status": entity.status,
"last_update": entity.timestamp.isoformat()
}
taskqueue.add(
url='/tasks/replicate-to-firebase',
params={'payload': json.dumps(payload)},
method='POST'
)
2. Writing the Firebase Sync Worker
The worker receives the task request on GAE, authenticates using service account credentials, and pushes the payload directly to the Firebase database reference:
Selective Projection Sync from Datastore to Firebase Realtime Database
Only replicate minimal, permission-scoped UI state projections to Firebase while keeping sensitive historical records inside backend Cloud Datastore / PostgreSQL tables.
About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)
Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 25+ years of production software engineering experience.