Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Cloud databases and DBaaS

Clear, exam-focused notes on cloud databases and Database-as-a-Service (DBaaS): definitions, key theorems (CAP, PACELC), availability and quorum formulas, worked examples (availability, quorum, cost), common mistakes, exam tips and quick-check questions.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Cloud databases and DBaaS matter because many real systems run their data layer in the cloud: an engineer uses DBaaS to deploy, scale, secure and operate databases without owning the physical servers. For exam-style design and evaluation questions, you must explain trade-offs (consistency, availability, cost) and compute availability/cost numbers used in design decisions.

Key ideas

Start with clear definitions (each term is bolded and defined before use):

  • Cloud database: a database that runs on cloud infrastructure and that is offered with cloud features such as elasticity, redundancy and managed operations. Use this term when discussing deployment on cloud provider resources (virtual machines, managed services).
  • DBaaS (Database-as-a-Service): a managed cloud service that provides database engines, automated backups, scaling, monitoring, patching and an API/console to users; customers do not manage hosts or storage directly.
  • IaaS (Infrastructure as a Service): cloud model offering virtual machines, networks and storage; the user installs and manages OS and database software.
  • PaaS (Platform as a Service): cloud model that provides runtime and middleware so users deploy applications without managing OS; some DBaaS products are PaaS-like.
  • SaaS (Software as a Service): ready-to-use software delivered over the web; less relevant here but contrasts with DBaaS as a platform.
  • Elasticity: ability to scale resources up/down automatically with load.
  • Multitenancy: single service instance serves multiple customers logically isolated from each other.
  • SLA (Service-Level Agreement): a promise from provider about metrics such as availability, usually as a percentage uptime over a time period.
  • RPO (Recovery Point Objective): maximum tolerable gap in data (time) after a failure; determines backup/PITR granularity.
  • RTO (Recovery Time Objective): target time to restore service after a failure; influences failover/restore design.
  • Shared responsibility model: provider secures the managed service and underlying infrastructure; tenant is responsible for data classification, access control, key management, network policies and configuration.

Important theorems and statements used in exams (state, assumptions, proof ideas):

  • CAP theorem (Brewer's theorem) — exact statement: In any distributed data store, it is impossible for a system to simultaneously provide all three guarantees: (C) Consistency, (A) Availability, and (P) Partition tolerance. Formally: under a network partition (node-to-node communication lost), a distributed system must choose between consistency and availability. Assumptions: asynchronous network, network partitions possible, nodes may fail but do not behave maliciously. Common exam derivation: show a write must either be accepted by some partition (violating consistency) or be rejected (violating availability) when partitions exist.

  • PACELC theorem — exact statement: If a partition (P) occurs, a distributed system must trade off between Availability (A) and Consistency (C); Else (E), when there is no partition, the system must trade off between Latency (L) and Consistency (C). This extends CAP by adding the latency/consistency trade-off in normal operation. Assumptions: same as CAP plus emphasis on latency as a design metric.

  • Quorum rule (Dynamo-style): For a replicated system with replication factor N, reads contacting R replicas and writes contacting W replicas, strong consistency (linearizability) is achieved if W + R > N under strict quorums (no sloppy quorum/hinted handoff), a total order on writes (e.g., via a leader), and a write is considered committed only after W replicas durably record it. University derivation: show any read set intersects the last-write acknowledged write set by pigeonhole principle: |read set| + |write set| > N => intersection non-empty, so a read that returns the latest among its responses sees the most recent committed write.

  • Availability of replicated independent nodes: If each replica has availability p (probability it is up), and replicas fail independently, system availability (at least one replica up) is 1 - (1 - p)^N. Assumptions: independence, identical p across replicas. Derivation: probability all N are down = (1 - p)^N, complement gives at least one up.

Design patterns and operational features to know:

  • Single-master (primary) vs multi-master replication; trade-offs: single-master simplifies writes and ordering (consistency) but is a single point for write throughput and failover complexity; multi-master increases availability and write locality but requires conflict resolution.
  • Synchronous vs asynchronous replication: synchronous ensures durability across replicas before ack (higher consistency, higher latency), asynchronous gives lower latency but risks data loss on failure.
  • Sharding (horizontal partitioning) splits data by key across nodes for scale; must pick shard key to balance load.
  • Backups, snapshots, point-in-time recovery (PITR): snapshots capture complete data at a time; PITR uses write-ahead logs to restore to a particular time.

What to draw in exam diagrams (describe exactly):

  • Draw a multi-tier diagram labelled left-to-right: Clients -> Load Balancer -> Application tier (stateless app servers) -> DBaaS control plane + managed DB instances. Under managed DB instances draw 3 replicas labelled Primary, Replica-1, Replica-2, and annotate network zones (AZ1, AZ2, AZ3). Label arrows: Client -> LB (HTTP/HTTPS), LB -> App (requests), App -> DBaaS endpoint (SQL/TCP connection). Also draw backup storage bucket connected to DBaaS control plane and label 'automatic backups'.

Formulas

Availability_replica = p where p is probability a single replica is up (unitless; fraction between 0 and 1). Applies when replica availability is modelled probabilistically.

Availability_system_at_least_one = 1 - (1 - p)^N where N is number of independent replicas. Unitless. Applies under independence and identical p. Availability_series = ∏ A_i overall availability of serially dependent components equals the product of component availabilities A_i (assumes independent failures).

MTTF and MTBF are related but not identical (time unit: hours). MTTF applies to non-repairable items (time to first failure); MTBF applies to repairable items (time between failures). Do not equate them unless repair times are negligible and definitions align.

Availability = MTBF / (MTBF + MTTR) where MTBF is mean time between failures (hours) and MTTR is mean time to repair (hours). Unitless fraction. Applies for steady-state single repairable component.

Strong_consistency_condition_quorum: W + R > N where N = replication factor, W = number of replicas required to ack a write, R = number of replicas read from. Unitless counts. Applies to quorum-based replication.

Downtime_per_month = (1 - availability) × 30 × 24 × 60 downtime in minutes per month (approximate; assumes 30-day month).

Worked examples

  1. Availability of replicated DB (numerical, step-by-step) Given: replication factor N = 3, each replica availability p = 0.995 (99.5%). Compute probability at least one replica is up. Step 1: write formula: Availability_system = 1 - (1 - p)^N. Step 2: substitute: 1 - (1 - 0.995)^3 = 1 - (0.005)^3. Step 3: compute (0.005)^3 = 0.000000125. Step 4: 1 - 0.000000125 = 0.999999875. Answer: system availability = 0.999999875 (≈ 99.9999875%). Note assumptions: replica failures independent, identical p. In reality network partitions and correlated failures reduce this number.

  2. Quorum read/write example (algorithmic trace) System: N = 3 replicas. Choose W = 2 (writes must be acked by 2), R = 2 (reads consult 2). Check strong consistency: W + R = 4 > N => yes. Trace: client A writes value X=5. The write is propagated to replicas 1 and 2 and both ack (W satisfied). Replica 3 may be stale. A later client B reads: it queries two replicas (say 1 and 3). Since replica 1 has latest value, reader gets X=5 and returns latest. This satisfies strong consistency because read set intersected write set.

  3. Cost estimate example (model answer style, numbers for exam work) Task: Estimate monthly cost for small DBaaS deployment: one r5.small-equivalent instance billed at $0.10/hour, 100 GB storage at $0.10/GB-month, 1000 IOPS included, additional IOPS ignored. Use 30-day month. Step 1: instance hours = 24 × 30 = 720 hours. Instance cost = 720 × $0.10 = $72. Step 2: storage cost = 100 × $0.10 = $10. Step 3: total = $72 + $10 = $82 per month. Note: This is a simplified model; DBaaS pricing also includes backup storage, data transfer, IO costs. (Check provider pricing during design.)

Common mistakes

  • Confusing availability percentage with downtime minutes (not converting units).
  • Using W + R ≥ N instead of W + R > N (strict inequality matters for guarantee proofs).
  • Mixing synchronous and asynchronous replication semantics when explaining consistency and data-loss risk.
  • Saying DBaaS eliminates security responsibilities; in reality some responsibilities remain with the tenant (shared responsibility model).

For your exam

Question types you will see

  • Definitions and short notes: define DBaaS, cloud database, elasticity, multitenancy, SLA. Full-marks answer: concise definition, key properties, one line example.
  • Diagram and explanation: draw DBaaS architecture (clients, LB, app servers, DB nodes, replicas, backups) and explain data flow and failure handling. Full-marks answer: neat diagram (labels as described above), explanation of each component and its role in availability/scaling.
  • Derivation questions: prove CAP theorem implication or derive system availability for N replicas. Full-marks answer: state theorem, assumptions, short proof; for derivations show algebra steps and state assumptions.
  • Numerical problems: compute availability, downtime, or cost. Full-marks answer: write formula, substitute numbers, show arithmetic, state units and assumptions.
  • Short design questions: choose DB type for use-case (OLTP vs analytics, relational vs NoSQL) and justify with trade-offs (consistency, latency, scalability). Full-marks answer: name the service, explain one-line trade-offs, map to CAP/PACELC where relevant.

Quick check

  1. Define DBaaS in one sentence.
  2. State the CAP theorem precisely (include when the trade-off applies).
  3. For N = 4 replicas each p = 0.99, compute system availability for at least one replica up (formula and number). Answers: 1) DBaaS is a managed cloud service that provides a database engine and automates operational tasks so users do not manage servers. 2) CAP theorem: under a network partition, a distributed data store must choose between consistency and availability; it cannot provide all three C, A and P simultaneously. 3) Availability = 1 - (1 - 0.99)^4 = 1 - (0.01)^4 = 1 - 1e-8 = 0.99999999 (≈ 99.999999%).

(Reviewer note: I have explained terms simply and included exact theorem statements and algebraic derivations where exams ask. I have kept provider-specific numbers minimal and marked uncertain items below.)

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?