Cloud Databases & Database-as-a-Service
Cloud database ও DBaaS — AWS, GCP, Azure
1. From "I run Postgres on a server" to "the cloud runs Postgres for me"
Five years ago, "having a database" meant renting a Linux box, installing PostgreSQL or MySQL, configuring backups, hoping the disk would not fail at 3 a.m. Today, none of that is necessary. Every major cloud provider — AWS, GCP, Azure — and a flock of independent vendors offer managed databases: you click a button, get a connection string, and they handle the rest. This is Database-as-a-Service (DBaaS).
This module is a tour of the modern landscape: managed RDBMS (RDS, Aurora, Cloud SQL), serverless SQL (Aurora Serverless, Neon, PlanetScale, Turso), managed NoSQL (DynamoDB, Cosmos DB, Atlas), data warehouses (BigQuery, Snowflake, Redshift, Databricks), and globally-consistent engines (Spanner, CockroachDB). At the end you will get a decision tree — a one-page cheat sheet you can use the next time someone asks "which database should we pick?"
2. Managed Relational Databases
The simplest cloud database story: take Postgres or MySQL, run it on cloud-provider infrastructure, wrap it in a console + API for backups, replicas and patching. The user's app code is unchanged — same SQL, same drivers, same JDBC URL.
| Service | Provider | Compatible with | Notable feature |
|---|---|---|---|
| RDS | AWS | Postgres, MySQL, MariaDB, SQL Server, Oracle | One-click multi-AZ replicas, automated backups. |
| Aurora | AWS | Postgres- & MySQL-wire compatible | AWS-rewritten storage layer — 5× MySQL throughput, 3× Postgres, 6-way replication. |
| Cloud SQL | GCP | Postgres, MySQL, SQL Server | Tight IAM & VPC integration with the rest of GCP. |
| AlloyDB | GCP | Postgres-compatible | Google's Aurora-equivalent — columnar accelerator for HTAP. |
| Azure SQL Database | Azure | SQL Server | Hyperscale tier separates compute from storage to 100 TB. |
| Azure Database for Postgres | Azure | Postgres | Flexible Server + read replicas across regions. |
3. Serverless SQL — The 2024-26 Wave
"Managed" still meant you pick an instance size and pay for it 24×7. The new wave is serverless: storage is decoupled from compute, the compute scales to zero when idle, and you pay for what you actually use (CPU-seconds, GB-stored, queries-run).
| Service | Compatible with | Killer feature |
|---|---|---|
| Aurora Serverless v2 | Postgres / MySQL | Auto-scales ACUs in seconds; same tooling as Aurora. |
| Neon | Postgres | True branch-per-feature like Git; instant copy-on-write database branches for every PR. |
| Supabase | Postgres | Postgres + auto-REST + auth + realtime + storage in one platform. |
| PlanetScale | MySQL (Vitess) | Branch-based schema migrations, zero-downtime deploys, massive horizontal sharding. |
| Turso | SQLite (libSQL) | SQLite at the edge — replicated to dozens of regions for ~10 ms global reads. |
| D1 | SQLite | Cloudflare's edge SQLite, integrated with Workers. |
| Xata / Tembo | Postgres | Postgres + search + AI embeddings bundled. |
4. Managed NoSQL
Every NoSQL family from previous modules is now available as a fully managed service. They typically charge per-request and per-GB, scale horizontally to almost any size, and replace "DBA for ops" with "good schema design" as the hard part.
📄 Document & Wide-column
- DynamoDB (AWS) — single-digit ms latency at any scale, used by Amazon.com itself.
- Cosmos DB (Azure) — multi-model: SQL API, Mongo API, Cassandra API, Gremlin.
- MongoDB Atlas — managed Mongo on AWS, GCP or Azure.
- Firestore / Firebase (GCP) — realtime sync to mobile/web clients.
🔑 Key-value & Cache
- Redis Cloud, ElastiCache (AWS), Memorystore (GCP).
- Upstash — pay-per-request serverless Redis & Kafka.
- DynamoDB DAX — DAX in-memory cache in front of DynamoDB.
🔍 Search
- Elasticsearch / OpenSearch Service — full-text + analytics.
- Algolia, Typesense Cloud, Meilisearch Cloud — instant search-as-a-service.
5. Analytics Warehouses & Lakehouses
OLTP databases (RDS, Aurora) are tuned for many small transactions per second. OLAP warehouses are the opposite — billions of rows scanned per query, but only a few queries per minute. They use columnar storage, massive parallelism and decouple compute from storage so you can scan a petabyte in seconds and pay only for those seconds.
| Service | Provider | Pricing flavour | Strength |
|---|---|---|---|
| BigQuery | GCP | Per-byte scanned (or flat-rate slots) | Truly serverless — no cluster to manage. Scales to exabytes. |
| Snowflake | Multi-cloud | Per-warehouse second | Multiple isolated "virtual warehouses" sharing one storage layer. |
| Redshift / Redshift Serverless | AWS | Per-node hour or per-RPU second | Tight integration with the AWS data ecosystem. |
| Azure Synapse / Microsoft Fabric | Azure | Per-DWU hour | Combines warehouse, lake and Power BI in one workspace. |
| Databricks SQL | Multi-cloud | Per-DBU second | Lakehouse — Parquet on object store + ACID via Delta Lake. |
| ClickHouse Cloud | Multi-cloud | Per-CU minute | Sub-second analytics over billions of rows. |
| DuckDB / MotherDuck | Hybrid local/cloud | Per-CU hour | The "SQLite of analytics" — surprisingly capable for small teams. |
6. Globally-Consistent & NewSQL Engines
For services that must be both strongly consistent and geographically distributed — payments, ad-serving, multiplayer games — a special class of database has emerged. They promise the SQL/transactions story of Postgres with the horizontal scale of NoSQL.
- Google Cloud Spanner — globally consistent SQL across continents using TrueTime atomic clocks. Powers AdWords, Gmail metadata.
- CockroachDB — Postgres-wire compatible, multi-region, open-source core.
- YugabyteDB — Postgres-compatible, distributed, cloud-native.
- TiDB — MySQL-compatible HTAP database from PingCAP.
- FaunaDB — serverless ACID document DB with cross-region transactions.
7. Pricing Models & Hidden Costs
Understanding the bill is half the job of a cloud database engineer. There are roughly three pricing styles:
| Model | Examples | Best when | Watch out for |
|---|---|---|---|
| Provisioned (per instance hour) | RDS, Cloud SQL, Aurora normal mode | Predictable, steady traffic. | You pay for idle capacity 24×7. |
| Serverless / Auto-scale (per CPU-second + per GB) | Aurora Serverless, Neon, Cosmos DB autoscale | Spiky or bursty workloads, dev/stage, hobby apps. | Cold-start latency; runaway bills if a query loops. |
| Per request / per byte | DynamoDB on-demand, BigQuery flat-rate-off, Upstash, Atlas Vector Search | Unpredictable traffic, very read-heavy. | An accidental 1-TB scan or a viral burst can cost thousands in minutes. |
✅ Benefits of DBaaS
- No 3 a.m. pages — provider handles failover & patching.
- Push-button replicas, snapshots, point-in-time restore.
- Encryption at rest & TLS in transit by default.
- Compliance frameworks (SOC2, ISO 27001, PCI) inherited.
- Elastic scaling — up and down — within minutes.
⚠️ Trade-offs
- Vendor lock-in — DynamoDB or Spanner code does not migrate cleanly to anything else.
- Egress fees — moving data out of the cloud is expensive.
- Cost spikes — pay-per-query models can ruin a month if a single bad query escapes.
- Reduced control — no
SHOW PROCESSLIST-equivalent on some managed services; debugging hard problems is harder. - Compliance & data residency — Bangladesh Bank, for instance, requires certain data inside Bangladesh.
# Spin up a small managed Postgres on AWS RDS in 30 seconds
aws rds create-db-instance \
--db-instance-identifier shopdb-prod \
--engine postgres \
--engine-version 16.3 \
--db-instance-class db.t4g.medium \
--allocated-storage 20 \
--master-username appadmin \
--master-user-password "$DB_PWD" \
--backup-retention-period 7 \
--multi-az \
--storage-encrypted \
--publicly-accessible false
8. The "Which Database?" Decision Tree
A condensed chooser you can use the next time someone asks "which database do we pick?". Read top-to-bottom; the first matching row wins.
| If your need is… | Pick… | Why |
|---|---|---|
| "A normal web/SaaS app, mostly Postgres" | RDS Postgres / Aurora Postgres / Cloud SQL Postgres | Boring, proven, full SQL, ACID, strong tooling. |
| "Hobby project, 100% serverless, branch-per-PR" | Neon (Postgres) or Supabase | Scale-to-zero, instant branches, Git-style workflow. |
| "Edge app — global <30 ms reads" | Turso (libSQL) or Cloudflare D1 | SQLite replicated to dozens of regions. |
| "Massive horizontal MySQL scaling" | PlanetScale (Vitess) | Sharding done for you; safe online schema changes. |
| "Predictable single-digit-ms key-value at any scale" | DynamoDB | Battle-tested, fully serverless, AWS-deeply integrated. |
| "Real-time mobile/web sync (chat, presence, dashboards)" | Firestore or Supabase Realtime | Push-based change feeds to clients out of the box. |
| "Petabyte analytics, occasional queries" | BigQuery | Per-byte pricing — pay only for the columns you scan. |
| "Petabyte analytics, many concurrent users" | Snowflake or Databricks SQL | Independent virtual warehouses isolate workloads. |
| "Sub-second analytics dashboard over billions of rows" | ClickHouse Cloud | Specialised columnar engine with per-row vector ops. |
| "Globally consistent SQL, multi-region writes" | Spanner or CockroachDB | External consistency + horizontal scale; accept the latency cost. |
| "Just embeddings & RAG" | pgvector on Neon/RDS, or Pinecone | (See Module 50.) |
| "Bangladesh Bank-regulated workload, must stay onshore" | Self-hosted Postgres + replicas in BD data center | Compliance overrides convenience. |
9. Glossary (শব্দকোষ)
| Term | Meaning | বাংলায় |
|---|---|---|
| DBaaS | Database-as-a-Service — managed database hosted by a vendor. | Vendor-পরিচালিত managed database service। |
| Multi-AZ | Replicas across separate Availability Zones for failover. | আলাদা Availability Zone-এ replica রেখে high-availability। |
| Serverless DB | Compute scales to zero when idle; pay-per-use. | Idle হলে compute বন্ধ হয়ে যায়, ব্যবহার অনুযায়ী bill। |
| Egress fee | Charge for data leaving the cloud provider's network. | Cloud provider-এর বাইরে data নেওয়ার fee। |
| OLTP / OLAP | Transactional vs analytical workloads. | Transaction-ভিত্তিক vs analytics-ভিত্তিক load। |
| Lakehouse | Data lake (object storage) + warehouse-style ACID + SQL. | Object storage-এর উপরে warehouse-সদৃশ SQL ও ACID। |
| NewSQL | SQL + transactions + horizontal scale (Spanner, CockroachDB, TiDB). | SQL ও ACID বজায় রেখে horizontal scaling করা যায় এমন database। |
10. Practice Problems
Decision-style problems — there is sometimes more than one defensible answer. Use the decision tree from §8 as your reference.
-
In two sentences, distinguish RDS from Aurora.RDS এবং Aurora-র পার্থক্য দুই বাক্যে লিখুন।
✨ Show Answer
Answer: RDS runs the standard upstream Postgres or MySQL engine on managed EC2 hosts. Aurora keeps the same wire-protocols and SQL but replaces the storage engine with AWS's own distributed, multi-AZ-replicated layer — yielding higher throughput and durability at higher cost.
RDS = standard Postgres/MySQL managed। Aurora = একই wire-protocol, কিন্তু AWS-এর নিজের লেখা distributed storage — দ্রুততর ও বেশি durable, দাম একটু বেশি।
-
A Bangladeshi e-learning startup with spiky traffic (exam nights) needs Postgres. Which DBaaS is most cost-effective and why?পরীক্ষার রাতে ট্রাফিক ১০× বেড়ে যায় এমন একটি e-learning startup-এর জন্য কোন DBaaS সবচেয়ে cost-effective?
✨ Show Answer
Answer: A serverless Postgres — Neon, Supabase or Aurora Serverless v2. They scale up automatically during exam-night spikes and scale almost to zero in the off-hours, so the startup pays for actual usage rather than a 24×7 large instance. Neon's branch feature also makes preview environments per pull request trivial.
Serverless Postgres (Neon / Aurora Serverless v2) — peak-এ auto-scale up, off-peak-এ প্রায় শূন্য, তাই bill কম।
-
Why is DynamoDB sometimes cheaper than Postgres at very high QPS?খুব বেশি QPS-এ DynamoDB কখনও কখনও Postgres-এর চেয়ে সস্তা কেন?
✨ Show Answer
Answer: A Postgres instance has a fixed cost regardless of QPS, and you must over-provision for peak load. DynamoDB charges per request and scales horizontally with no instance to provision, so at predictable, very high QPS the per-request price often beats the cost of a similarly sized Postgres cluster — and it never wakes you at 3 a.m.
Postgres instance fixed খরচ + peak-এর জন্য over-provision; DynamoDB per-request — তাই উচ্চ QPS-এ DynamoDB সস্তা হতে পারে।
-
Write the AWS CLI command to create an encrypted, multi-AZ Postgres 16 RDS instance with 7-day backups.Encrypted multi-AZ Postgres 16 RDS instance তৈরি করার AWS CLI কমান্ড লিখুন।
✨ Show Answer
ans4.shaws rds create-db-instance \ --db-instance-identifier myapp-prod \ --engine postgres --engine-version 16.3 \ --db-instance-class db.t4g.medium \ --allocated-storage 20 \ --master-username dbadmin --master-user-password "$DB_PWD" \ --multi-az --storage-encrypted \ --backup-retention-period 7 -
Your CTO suggests Spanner for a Bangladeshi food-delivery startup running entirely in one country. Why might that be overkill?শুধু বাংলাদেশে চলা food-delivery startup-এর জন্য Spanner কেন বেশি?
✨ Show Answer
Answer: Spanner's value is global, externally-consistent multi-region writes — paid for with higher latency and far higher cost. A single-country app gets the same correctness from a regional Postgres at a fraction of the price. Spanner only pays off when active-active multi-region writes are a hard requirement.
Spanner-এর মূল মূল্য বহু-region active-active write — শুধু বাংলাদেশে চললে regional Postgres-ই যথেষ্ট, খরচ অনেক কম।
-
Name two distinct ways BigQuery's pricing can surprise a careless engineer.BigQuery-র pricing-এ কোন দুটি অপ্রত্যাশিত কারণে bill বেড়ে যেতে পারে?
✨ Show Answer
Answer: (1)
SELECT *on a wide table scans every column, billing per byte — even though the user only needed two columns. (2) Querying without partition pruning (WHERE _PARTITIONTIME > …) re-scans the entire historical dataset every time, multiplying cost by years of accumulated data.(১)
SELECT *— সব column scan হয়, bill বাড়ে। (২) Partition filter ছাড়া query — পুরো history scan হয়, খরচ বহুগুণ। -
Which managed database would you pick for a Cloudflare-Workers app that must respond in < 50 ms from Singapore, Frankfurt and Sao Paulo?Singapore, Frankfurt, Sao Paulo — সব region থেকে < 50 ms response চাইলে কোন DB?
✨ Show Answer
Answer: Turso (libSQL) or Cloudflare D1 — both replicate SQLite to many edge regions, giving sub-50-ms reads worldwide. For writes only one primary region exists, but for read-heavy edge apps that is the right trade.
Turso অথবা Cloudflare D1 — SQLite globally replicate করে, edge থেকে দ্রুত read পাওয়া যায়।
-
Explain "egress fee" in one paragraph, with an example.Egress fee এক অনুচ্ছেদে উদাহরণসহ বুঝিয়ে বলুন।
✨ Show Answer
Answer: Cloud providers charge for data leaving their network — typically 5–9 cents per GB. Hosting your database on AWS in Mumbai but serving an analytics dashboard from a Singapore VPS means every query result crosses regions and racks up egress fees. Often this single line item is bigger than the database compute cost itself, and is the most common "Why is our cloud bill so high?" answer.
Cloud-এর বাইরে data নেওয়ার fee — সাধারণত প্রতি GB-তে ৫-৯ সেন্ট। DB এক region-এ, app অন্য region-এ থাকলে এই fee অনেক বেড়ে যায়।
-
A Bangladesh-Bank-regulated mobile-banking workload requires data to stay inside Bangladesh. How does that change your DBaaS choice?Bangladesh Bank-নিয়ন্ত্রিত workload — DBaaS পছন্দে এটি কীভাবে প্রভাব ফেলে?
✨ Show Answer
Answer: Compliance overrides convenience. None of the major hyperscalers run a region inside Bangladesh today, so a fully managed AWS/GCP/Azure database is usually disqualified. The realistic options are: self-hosted Postgres on a local data centre, a regulated on-shore cloud (such as a local provider's managed offering), or Oracle/Microsoft solutions deployed on premises with a vendor support contract. Always check the latest BB Cyber Security Guidelines before committing.
Compliance > convenience। বাংলাদেশে major cloud-এর region নেই, তাই self-hosted Postgres বা local data-center-ভিত্তিক managed service বেছে নিতে হবে। সর্বশেষ BB-র Cyber Security Guidelines যাচাই করা আবশ্যক।
-
In one sentence: when should you NOT use a serverless database?এক বাক্যে — কখন serverless DB ব্যবহার করা ঠিক নয়?
✨ Show Answer
Answer: When traffic is high and steady — at constant heavy load, a provisioned reserved instance is usually cheaper, and you avoid the cold-start latency some serverless engines incur after idle periods.
যখন traffic ধারাবাহিকভাবে বেশি — তখন provisioned reserved instance সস্তা ও cold-start-হীন।
Summary — Module 51
Cloud databases turned operations into a checkbox. Pick a flavour — managed RDBMS (RDS, Aurora, Cloud SQL) for boring SQL apps, serverless SQL (Neon, PlanetScale, Turso) for spiky workloads or edge apps, managed NoSQL (DynamoDB, Cosmos DB, Atlas) for scale and predictable shape, warehouses (BigQuery, Snowflake, Databricks) for analytics, and NewSQL (Spanner, CockroachDB) for global consistency. The trade-offs are pricing surprises, vendor lock-in, egress fees and reduced visibility — but for 95% of teams the productivity gain is worth it. The right answer is usually "boring Postgres, then add specialised stores when you have a specific bottleneck."