2020-02-05 04:17:08+00:00

Google Cloud offers two modes for its serverless NoSQL database: Firestore Native Mode and Datastore Mode. While Firestore Native mode provides real-time updates and client SDKs, it enforces a lock limit of 1 write per second per document. For telemetry systems updating status records frequently, this can cause transaction aborts.

Analyzing database capabilities reveals that for backend-heavy, high-throughput query applications, Datastore Mode remains the optimal choice.


1. Evaluating Write Locks

In native Firestore, updating a single document more than once per second triggers write contention. In Datastore mode, document updates are distributed across physical entity groups, bypassing this lock boundary for isolated entries.

2. Query Compatibility Issues

Datastore mode supports key projections and ancestor queries, which allow you to query data hierarchies efficiently. Migrating to native Firestore requires rewriting the query architecture to use subcollections and query indexes:

# Example of structured ancestor query in Python GAE
from google.cloud import ndb

class DeviceTelemetry(ndb.Model):
    status = ndb.StringProperty()
    timestamp = ndb.DateTimeProperty(auto_now_add=True)

def get_device_logs(device_key):
    # Query ancestor groups efficiently in Datastore mode
    return DeviceTelemetry.query(ancestor=device_key).order(-DeviceTelemetry.timestamp).fetch(50)

Keeping Datastore mode avoids rewrite risks and offers high transaction throughput for device-level updates.

Optimistic Concurrency vs. Pessimistic Locks in Firestore

When migrating high-contention counters or ledger balances between Datastore Mode and Native Firestore, shard high-frequency write documents or batch updates via task queues to avoid transaction retry storms.


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