Cloud Engineer & GCP Engineer: Scaling High-Throughput NoSQL on AWS DynamoDB, Cloud Datastore & Firestore
Distributed NoSQL engines—AWS DynamoDB, Google Cloud Datastore, and Cloud Firestore—deliver single-digit millisecond latency at petabyte scale only when partition keys, composite sort keys, and index configurations are engineered around actual access patterns. Treating DynamoDB or Firestore like a relational database with ad-hoc filter scans causes hot-partition throttling (ProvisionedThroughputExceededException / 429 Too Many Requests) and exploding read-unit bills. As a Cloud Engineer and GCP Engineer, I design single-table DynamoDB schemas and write-sharded Firestore collections for high-throughput production systems.
1. Single-Table Design & Write-Sharded Partition Keys
When a single tenant or live event generates 15,000 writes per second, routing every item to the same partition key (PK = "TENANT#acme") exceeds DynamoDB's 1,000 WCU per physical partition limit and Firestore's lexicographical prefix hotspot limit. We distribute write load across N deterministic hash buckets on write and scatter-gather in parallel on read:
import asyncio
import hashlib
from typing import Any
SHARD_COUNT = 16
def compute_sharded_pk(tenant_id: str, entity_id: str) -> str:
digest = hashlib.md5(f"{tenant_id}:{entity_id}".encode("utf-8")).digest()
shard_id = digest[0] % SHARD_COUNT
return f"TENANT#{tenant_id}#SHARD#{shard_id:02d}"
async def query_all_tenant_shards(
ddb_table: Any,
tenant_id: str,
sk_prefix: str,
) -> list[dict]:
async def fetch_shard(shard_idx: int) -> list[dict]:
pk = f"TENANT#{tenant_id}#SHARD#{shard_idx:02d}"
resp = await asyncio.to_thread(
ddb_table.query,
KeyConditionExpression="PK = :pk AND begins_with(SK, :sk)",
ExpressionAttributeValues={":pk": pk, ":sk": sk_prefix},
)
return resp.get("Items", [])
shard_results = await asyncio.gather(*(fetch_shard(i) for i in range(SHARD_COUNT)))
merged = [item for sublist in shard_results for item in sublist]
merged.sort(key=lambda r: r["SK"], reverse=True)
return merged
2. Eliminating Index Fan-Out & Optimizing WCU / Read Unit Costs
In Google Cloud Datastore and Firestore, every indexed array element or composite index multiplies write amplification and storage cost. By explicitly marking large JSON state blobs as unindexed (exclude_from_indexes)—as demonstrated in our DynamoDB WCU cost optimization guide and Datastore Mode vs. Native Firestore Locks analysis—we routinely reduce monthly NoSQL bills by 55–75% without sacrificing p99 query latency.
Need a Cloud Engineer or GCP Engineer to scale your DynamoDB, Datastore, or Firestore architecture? Book a 1-Day Engineering Sprint.