Cloud Databases & Database-as-a-Service

Cloud database ও DBaaS — AWS, GCP, Azure

Read: ~40 min Intermediate 10 practice problems 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).

একসময় database চালানো মানে ছিল Linux server ভাড়া করা, manually PostgreSQL/MySQL install করা, backup script লেখা, রাত ৩টায় disk fail হলে নিজেই ছুটে যাওয়া। আজ এসব দরকার নেই — AWS, GCP, Azure এবং Neon/PlanetScale-এর মতো vendor একটা ক্লিক-এই আপনাকে database দিয়ে দেবে, backup, replication, failover সব নিজেরা সামলাবে। এটিই 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.

ServiceProviderCompatible withNotable feature
RDSAWSPostgres, MySQL, MariaDB, SQL Server, OracleOne-click multi-AZ replicas, automated backups.
AuroraAWSPostgres- & MySQL-wire compatibleAWS-rewritten storage layer — 5× MySQL throughput, 3× Postgres, 6-way replication.
Cloud SQLGCPPostgres, MySQL, SQL ServerTight IAM & VPC integration with the rest of GCP.
AlloyDBGCPPostgres-compatibleGoogle's Aurora-equivalent — columnar accelerator for HTAP.
Azure SQL DatabaseAzureSQL ServerHyperscale tier separates compute from storage to 100 TB.
Azure Database for PostgresAzurePostgresFlexible Server + read replicas across regions.
মূল কথা: RDS / Cloud SQL / Azure SQL — তিনটিই একই ধরনের service, কেবল cloud আলাদা। যেখানে আপনার বাকি app চলছে সেই cloud-এর managed database বেছে নেওয়াই সবচেয়ে সহজ ও দ্রুত (latency, networking এবং billing সব এক জায়গায় থাকে)।
Aurora vs RDS — যখন কোনটি RDS হলো standard Postgres/MySQL on EC2-হাল্কা wrapper। Aurora হলো AWS-এর নিজের লেখা storage engine যেটি Postgres/MySQL-এর wire-protocol মেনে চলে। দাম একটু বেশি, কিন্তু throughput ও durability অনেক বেশি — production OLTP-এর জন্য সাধারণত Aurora বেছে নেওয়া হয়।

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).

ServiceCompatible withKiller feature
Aurora Serverless v2Postgres / MySQLAuto-scales ACUs in seconds; same tooling as Aurora.
NeonPostgresTrue branch-per-feature like Git; instant copy-on-write database branches for every PR.
SupabasePostgresPostgres + auto-REST + auth + realtime + storage in one platform.
PlanetScaleMySQL (Vitess)Branch-based schema migrations, zero-downtime deploys, massive horizontal sharding.
TursoSQLite (libSQL)SQLite at the edge — replicated to dozens of regions for ~10 ms global reads.
D1SQLiteCloudflare's edge SQLite, integrated with Workers.
Xata / TemboPostgresPostgres + search + AI embeddings bundled.
Serverless DB-এর জাদু: idle থাকলে compute pause হয়ে যায়, traffic এলে কয়েক সেকেন্ডে scale up। Hobby project, internal tool, বা spiky traffic-এর startup-এর জন্য আদর্শ — মাসের bill 5-10 ডলারে নেমে আসে। তবে predictable heavy-traffic system-এ (যেমন bKash-এর core ledger) provisioned instance বেশি cost-efficient হতে পারে।

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.
DynamoDB-র সবচেয়ে বড় চমক হলো — যত request-ই দেন, latency ১০ ms-এর নিচে থাকে। তবে এটি SQL নয়; query pattern আগে থেকেই জানতে হবে এবং সেই pattern অনুযায়ী partition key ও sort key ডিজাইন করতে হবে। ভুল key বেছে নিলে scaling এবং cost — দুটোই হাতছাড়া হতে পারে।

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.

ServiceProviderPricing flavourStrength
BigQueryGCPPer-byte scanned (or flat-rate slots)Truly serverless — no cluster to manage. Scales to exabytes.
SnowflakeMulti-cloudPer-warehouse secondMultiple isolated "virtual warehouses" sharing one storage layer.
Redshift / Redshift ServerlessAWSPer-node hour or per-RPU secondTight integration with the AWS data ecosystem.
Azure Synapse / Microsoft FabricAzurePer-DWU hourCombines warehouse, lake and Power BI in one workspace.
Databricks SQLMulti-cloudPer-DBU secondLakehouse — Parquet on object store + ACID via Delta Lake.
ClickHouse CloudMulti-cloudPer-CU minuteSub-second analytics over billions of rows.
DuckDB / MotherDuckHybrid local/cloudPer-CU hourThe "SQLite of analytics" — surprisingly capable for small teams.
Warehouse vs OLTP-এর মূল পার্থক্য — OLTP system প্রতি সেকেন্ডে হাজার-হাজার ছোট transaction handle করে (একটি bKash transfer, একটি order)। Warehouse-এ আপনি বছরের পুরো ডেটার ওপর ১টি বিশাল aggregation চালান (এক বছরে বিভাগ-অনুযায়ী মোট বিক্রি)। দুই system দুই ধরনের কাজের জন্য — তাই বেশিরভাগ company-তে দুটোই থাকে।

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.
The price of global consistency All of these systems pay the speed-of-light tax. A cross-continent commit takes ~100 ms minimum because data must round-trip between regions. If your app does 50 sequential writes during a request, you have just spent 5 seconds. Designing for "few large transactions" instead of "many small ones" becomes essential.
মনে রাখুন: Spanner বা CockroachDB জাদুকরী মনে হলেও, একই data দুটি মহাদেশে synchronously commit করতে আলোর গতি (~100 ms round-trip) লাগে। তাই app design-এ অনেক ছোট transaction-এর বদলে কম কিন্তু বড় transaction ব্যবহার করতে হয়।

7. Pricing Models & Hidden Costs

Understanding the bill is half the job of a cloud database engineer. There are roughly three pricing styles:

ModelExamplesBest whenWatch out for
Provisioned (per instance hour)RDS, Cloud SQL, Aurora normal modePredictable, steady traffic.You pay for idle capacity 24×7.
Serverless / Auto-scale (per CPU-second + per GB)Aurora Serverless, Neon, Cosmos DB autoscaleSpiky or bursty workloads, dev/stage, hobby apps.Cold-start latency; runaway bills if a query loops.
Per request / per byteDynamoDB on-demand, BigQuery flat-rate-off, Upstash, Atlas Vector SearchUnpredictable 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.
aws.sh
# 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 PostgresBoring, proven, full SQL, ACID, strong tooling.
"Hobby project, 100% serverless, branch-per-PR"Neon (Postgres) or SupabaseScale-to-zero, instant branches, Git-style workflow.
"Edge app — global <30 ms reads"Turso (libSQL) or Cloudflare D1SQLite 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"DynamoDBBattle-tested, fully serverless, AWS-deeply integrated.
"Real-time mobile/web sync (chat, presence, dashboards)"Firestore or Supabase RealtimePush-based change feeds to clients out of the box.
"Petabyte analytics, occasional queries"BigQueryPer-byte pricing — pay only for the columns you scan.
"Petabyte analytics, many concurrent users"Snowflake or Databricks SQLIndependent virtual warehouses isolate workloads.
"Sub-second analytics dashboard over billions of rows"ClickHouse CloudSpecialised columnar engine with per-row vector ops.
"Globally consistent SQL, multi-region writes"Spanner or CockroachDBExternal 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 centerCompliance overrides convenience.
সবচেয়ে বড় ভুল হলো hype দেখে DB বেছে নেওয়া। ৯৫%-এর বেশি startup-এর জন্য Postgres-ই যথেষ্ট। আপনি স্পষ্ট bottleneck না দেখা পর্যন্ত Spanner বা CockroachDB-র দিকে যাবেন না; স্পষ্ট key-value pattern না হওয়া পর্যন্ত DynamoDB-তে যাবেন না; warehouse-এর প্রয়োজন না হওয়া পর্যন্ত Snowflake-এ যাবেন না। সঠিক উত্তর প্রায়ই হলো — "আপাতত Postgres, পরে দরকার হলে অন্যটা যোগ করব।"

9. Glossary (শব্দকোষ)

TermMeaningবাংলায়
DBaaSDatabase-as-a-Service — managed database hosted by a vendor.Vendor-পরিচালিত managed database service।
Multi-AZReplicas across separate Availability Zones for failover.আলাদা Availability Zone-এ replica রেখে high-availability।
Serverless DBCompute scales to zero when idle; pay-per-use.Idle হলে compute বন্ধ হয়ে যায়, ব্যবহার অনুযায়ী bill।
Egress feeCharge for data leaving the cloud provider's network.Cloud provider-এর বাইরে data নেওয়ার fee।
OLTP / OLAPTransactional vs analytical workloads.Transaction-ভিত্তিক vs analytics-ভিত্তিক load।
LakehouseData lake (object storage) + warehouse-style ACID + SQL.Object storage-এর উপরে warehouse-সদৃশ SQL ও ACID।
NewSQLSQL + 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.

এগুলো বেশিরভাগই decision-type প্রশ্ন। উত্তর দেওয়ার সময় কেন এই DB বেছে নিচ্ছেন সেটি স্পষ্ট করে লিখুন।
  1. 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, দাম একটু বেশি।

  2. 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 কম।

  3. 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 সস্তা হতে পারে।

  4. 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.sh
    aws 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
  5. 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-ই যথেষ্ট, খরচ অনেক কম।

  6. 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 হয়, খরচ বহুগুণ।

  7. 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 পাওয়া যায়।

  8. 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 অনেক বেড়ে যায়।

  9. 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 যাচাই করা আবশ্যক।

  10. 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."

DBaaS কাজটা সহজ করে দিয়েছে — ops-এর ৯০% AWS/GCP/Azure সামলাচ্ছে। বেশিরভাগ team-এর জন্য সঠিক সিদ্ধান্ত "boring Postgres" দিয়ে শুরু করা; স্পষ্ট bottleneck দেখা দিলে তবেই অন্য specialised store যোগ করা। Hype-এর পেছনে দৌড়ালে bill, lock-in আর complexity — তিনটিই বাড়বে।

Next Module → Course finale — ORMs, Drivers, Migrations & Polyglot Persistence.