IT276 Database Administration

Database AdministrationUnit 1015 min read

Cloud Databases: Models, Services, Security & Migration

Unit 10 of Database Administration explores cloud-based database architectures, deployment models (PaaS, SaaS, IaaS), security challenges, migration strategies, and real-world use cases like eSewa’s transaction logs and Daraz’s inventory databases. Covers cost optimization, compliance (GDPR, PCI-DSS), and hybrid cloud

Key Concepts and Cloud Database Models

1. What Are Cloud Databases?

Cloud databases are managed database services hosted on remote servers (cloud infrastructure) instead of on-premises hardware. They offer scalability, elasticity, and pay-as-you-go pricing, eliminating the need for physical maintenance.

Examples: AWS RDS, Google Cloud SQL, Azure SQL DBDBaaS (Database-as-a-Service)Fully automated: backups, patching, scalingManaged ServicesTypesUser manages DB software (e.g., self-hosted MySQL on AWS EC2IaaS (Infrastructure-as-a-Service)User manages data (e.g., Google App Engine Datastore)PaaS (Platform-as-a-Service)No DB management (e.g., Salesforce, Airtable)SaaS (Software-as-a-Service)Deployment ModelsCloud Databases
Hierarchical breakdown of cloud database types and deployment models

Why Use Cloud Databases?

  • Cost Efficiency: No upfront hardware costs; pay for usage.
  • Scalability: Auto-scaling handles traffic spikes (e.g., Daraz’s Black Friday sales).
  • High Availability: Multi-region replication ensures uptime (e.g., Ncell’s customer data).
  • Disaster Recovery: Built-in backups and failover (e.g., eSewa’s transaction logs).

2. Cloud Database Deployment Models

Cloud databases are categorized by service models and deployment models (NIST framework). The key distinction lies in who manages what:

Service Model Responsibility Example Use Case
IaaS User manages OS, middleware, and DB AWS EC2 + self-installed PostgreSQL Custom DB configurations (e.g., NEPSE’s trading data)
PaaS Provider manages OS, middleware; user manages data Google Cloud SQL, Azure SQL DB Rapid app development (e.g., Pathao’s ride-hailing DB)
SaaS Provider manages everything; user accesses via API Salesforce, Airtable Small businesses (e.g., local shops using Daraz Seller Center)

Deployment Models (Physical Location Control):

mindmap
  root((Deployment Models))
    Public Cloud
      Example: AWS, Azure, Google Cloud
      Pros: Low cost, scalable
      Cons: Less control, security risks
    Private Cloud
      Example: On-premises VMware, OpenStack
      Pros: Full control, compliance (e.g., bank core systems)
      Cons: High cost, maintenance overhead
    Hybrid Cloud
      Example: Ncell’s CRM (public cloud) + billing (private cloud)
      Pros: Balance of control and scalability
      Cons: Complex integration
    Multi-Cloud
      Example: eSewa (AWS + Azure for redundancy)
      Pros: Avoid vendor lock-in
      Cons: Management complexity

In the Real World

  1. eSewa’s Transaction Logs

    • Idea Used: Multi-cloud DBaaS (AWS Aurora + Azure SQL) for high availability.
    • How: eSewa replicates transaction data across AWS (primary) and Azure (backup) to prevent downtime during peak hours (e.g., Dashain festivals). Uses read replicas to distribute load.
  2. Daraz’s Inventory Database

    • Idea Used: Serverless PaaS (AWS DynamoDB) for auto-scaling.
    • How: DynamoDB handles millions of product queries per second during sales events (e.g., 6.6.6) without manual scaling. Uses partition keys (product_id) and secondary indexes (category, price_range) for fast lookups.
  3. Ncell’s Customer Data

    • Idea Used: Hybrid Cloud (Private Cloud for PII + Public Cloud for Analytics).
    • How: Sensitive customer data (phone numbers, billing) is stored in a private cloud (compliant with Nepal’s Telecom Regulatory Authority rules), while public cloud (Google BigQuery) is used for marketing analytics (e.g., predicting churn).

3. Cloud Database Services Comparison

Not all cloud databases are equal. Here’s how leading providers compare:

Aurora PrimaryAurora Replica (Kathmandu)Aurora Replica (Delhi)Aurora Replica (Singapore)Redis CacheNEPSE App
Multi-region Aurora + Redis architecture for NEPSE stock data
Feature AWS RDS Google Cloud SQL Azure SQL DB MongoDB Atlas
Database Engine MySQL, PostgreSQL, Oracle, SQL Server MySQL, PostgreSQL, SQL Server SQL Server, PostgreSQL MongoDB (NoSQL)
Scaling Vertical (increase instance size) or horizontal (read replicas) Auto-scaling for read replicas Elastic pools for multi-DB workloads Auto-sharding for collections
Serverless Option Aurora Serverless Cloud SQL Serverless Azure SQL Database (serverless tier) MongoDB Atlas (serverless)
Compliance SOC, ISO 27001, HIPAA GDPR, ISO 27001, HIPAA ISO 27001, GDPR, PCI-DSS SOC 2, GDPR, HIPAA
Best For Enterprise apps (e.g., NEPSE trading) Data analytics (e.g., NTC network logs) Microsoft ecosystem (e.g., banks) Unstructured data (e.g., Pathao’s ride history)

Worked Example: NEPSE’s Trading Database

  • Requirement: Handle 10,000+ trades/sec during market hours with zero downtime.
  • Solution:
    • Primary DB: AWS Aurora PostgreSQL (multi-AZ deployment for failover).
    • Read Replicas: 3 replicas in different regions (Kathmandu, Delhi, Singapore).
    • Caching: Amazon ElastiCache (Redis) for frequent queries (e.g., stock prices).
    • Backup: Automated snapshots + cross-region replication to Azure.
sequenceDiagram
    participant User
    participant NEPSE_App
    participant Aurora_Primary
    participant Aurora_Replica
    participant Redis_Cache

    User->>NEPSE_App: Request stock price (e.g., NEPSE:123)
    NEPSE_App->>Redis_Cache: Check cache
    alt Cache hit
        Redis_Cache-->>NEPSE_App: Return price
    else Cache miss
        NEPSE_App->>Aurora_Primary: Query DB
        Aurora_Primary-->>NEPSE_App: Return price
        NEPSE_App->>Redis_Cache: Update cache
    end

4. Security and Compliance in Cloud Databases

Cloud databases introduce new attack vectors (e.g., misconfigured IAM roles, data leaks in shared tenancy). Key risks and mitigations:

A. Shared Responsibility Model

Cloud ProviderPhysical security Network infrastructure Hypervisor securityCustomerData encryption IAM policies Patch management Application se
Shared responsibility model for cloud databases (AWS/Azure/Google vs. Customer)

B. Compliance Requirements

Standard Applicability Cloud Database Controls
GDPR EU/UK data (e.g., Nepalese expats using WhatsApp) Data residency, right to erasure, encryption
PCI-DSS Payment processing (e.g., Khalti, eSewa) Tokenization, access logs, network segmentation
HIPAA Healthcare data (e.g., hospitals using cloud EHR) Audit logs, role-based access, data masking
Nepal’s IT Act Government data (e.g., NTC, Ncell) Data localization, encryption, access controls

Example: Khalti’s PCI-DSS Compliance

  • Challenge: Store credit card tokens securely while processing payments.
  • Solution:
    • Encryption: AES-256 for data at rest (AWS KMS).
    • Tokenization: Replace card numbers with tokens (stored in AWS Secrets Manager).
    • Network: PCI-compliant VPC with private subnets and no public internet access to DB.

5. Database Migration to the Cloud

Migrating on-premises databases to the cloud involves 6 key phases:

AssessEvaluate currentDB and cloud readinessPlanChoose tools/strategies (e.g., AWS DMS)MigrateLift-and-shiftor replatformOptimizeResize, index,or refactor queriesSecureEnable encryption,IAM policiesMonitorSet up alerts (e.g., CloudWatch)
6-phase cloud migration workflow with Nepali exam focus

A. Assessment Tools

Tool Purpose Example Use Case
AWS Database Migration Service (DMS) Homogeneous/heterogeneous DB migration MySQL (on-prem) → Aurora PostgreSQL
Google Cloud’s Database Migration Service Minimal downtime migration SQL Server → Cloud SQL
Azure Data Migration Assistant Assess compatibility & performance Oracle → Azure SQL DB

B. Migration Strategies

Strategy Downtime Complexity Best For
Lift-and-Shift High Low Simple apps (e.g., legacy bank systems)
Replatforming Medium Medium Optimize for cloud (e.g., Ncell’s CRM)
Refactoring Low High Cloud-native apps (e.g., Pathao’s real-time DB)
Hybrid Migration Variable High Compliance-sensitive data (e.g., NEPSE)

Worked Example: NTC’s Network Log Migration

  • Challenge: Migrate 10TB of historical network logs from on-prem SQL Server to Google BigQuery with zero downtime.
  • Solution:
    1. Initial Load: Use AWS DMS to replicate data to a staging Aurora DB.
    2. Cutover: Switch read queries to Aurora while writes go to BigQuery via Change Data Capture (CDC).
    3. Validation: Compare record counts between old and new systems.

6. Cost Optimization in Cloud Databases

Cloud databases can become expensive if not optimized. Key levers:

0255075100On-Demand100Reserved Instances70Spot Instances50Savings Plans65
AWS RDS pricing models comparison (Nepali exam focus)

A. Pricing Models

Model Description Example
On-Demand Pay per second/hour (no commitment) AWS RDS (for unpredictable workloads)
Reserved Instances 1- or 3-year commitment (up to 75% discount) NEPSE’s trading DB (predictable load)
Spot Instances Bid for unused capacity (up to 90% cheaper) Batch processing (e.g., NTC’s nightly analytics)
Serverless Pay per request (no idle costs) MongoDB Atlas for variable traffic

B. Cost-Saving Techniques

  • Right-Sizing: Use AWS Compute Optimizer to adjust instance types.
  • Auto-Scaling: Enable horizontal scaling for read replicas (e.g., Daraz’s product catalog).
  • Storage Tiering: Move cold data to cheaper storage classes (e.g., S3 Glacier for backups).
  • Multi-Region vs. Single-Region: Single-region is cheaper but less resilient.

Example: Daraz’s Cost Optimization

  • Before: Used m5.2xlarge instances (fixed cost) for product DB.
  • After: Switched to Aurora Serverless + auto-scaling read replicas.
    • Savings: 60% reduction in costs during off-peak hours.
    • Performance: Handled Black Friday traffic (5x normal load) without manual scaling.

7. Performance Tuning for Cloud Databases

Cloud databases require different tuning than on-premises systems due to shared resources and auto-scaling.

A. Common Bottlenecks

Bottleneck Cloud-Specific Cause Solution
High Latency Cross-region replication delays Use multi-region read replicas (e.g., eSewa’s global users)
Throttling Shared storage I/O in multi-tenant clouds Use provisioned IOPS (e.g., AWS EBS io1)
Cold Starts Serverless databases (e.g., Aurora Serverless) Use minimum capacity or provisioned concurrency
Network Overhead Data transfer costs between regions Cache frequently accessed data (e.g., Redis for NEPSE stock prices)

B. Query Optimization

  • Use Read Replicas: Offload read-heavy queries (e.g., Daraz’s product searches).
  • Indexing: Cloud databases support global secondary indexes (e.g., DynamoDB).
  • Partitioning: Avoid hot partitions (e.g., Pathao’s ride_id as partition key).
  • Materialized Views: Pre-compute aggregations (e.g., Ncell’s monthly billing reports).

Example: eSewa’s Transaction Query Optimization

  • Problem: Slow queries during Dashain (high transaction volume).
  • Solution:
    • Added composite index on (user_id, transaction_date).
    • Used Aurora read replicas in Mumbai and Singapore for global users.
    • Result: Query time reduced from 500ms → 10ms.

Exam Tip

What to Expect in TU/PU Exams

  1. Short Questions (2-5 marks):

    • Define DBaaS, multi-cloud, or shared responsibility model.
    • Compare AWS RDS vs. Google Cloud SQL (focus on pricing, compliance).
    • Explain one migration strategy (e.g., lift-and-shift vs. refactoring).
  2. Long Questions (10-15 marks):

    • Case Study: Given a scenario (e.g., "Ncell wants to migrate its CRM to the cloud"), outline:
      • Deployment model (hybrid).
      • Security controls (encryption, IAM, PCI-DSS).
      • Cost optimization (reserved instances for core DB, serverless for analytics).
    • Diagram-Based: Draw a sequence diagram for a cloud DB transaction (e.g., Khalti payment flow) or a mindmap of cloud database services.
  3. Practical (NEB-style):

    • SQL Query: Write a query to optimize a cloud DB (e.g., add an index for a slow join).
    • Configuration: Describe how to enable auto-scaling in AWS RDS or set up a read replica in Azure SQL.

Key Formulas to Remember

  • Cloud Cost Calculation:
    Total Cost = (Instance Hours × Price/hr) + (Storage × Price/GB) + (Data Transfer × Price/GB)
    
  • Replica Lag Calculation (for high availability):
    Replica Lag (sec) = (Primary DB Write Speed) / (Network Bandwidth)
    
    Example: If primary DB writes at 1000 transactions/sec and network bandwidth is 100 Mbps, lag = 1000 / (100 × 10^6 bits/sec) ≈ 0.01 sec.

Common Pitfalls

  • Ignoring Data Transfer Costs: Moving 1TB of data between regions can cost $100+ (AWS pricing).
  • Over-Provisioning: Using m5.4xlarge when m5.xlarge suffices.
  • Neglecting Compliance: Storing PCI-DSS data in a public cloud without tokenization.

Based on the TU BITM syllabus for Database Administration (IT276), unit 10.

Discussion

Loading…