Stage 3 · Build
Databases in Kubernetes
Managed vs Self-Hosted
When to use Azure Database for PostgreSQL, ElastiCache, Atlas vs self-host.
Decision Matrix
The managed vs self-hosted decision depends on team size, operational expertise, compliance requirements, and cost sensitivity. There is no universally correct answer — each workload has different tradeoffs.
| Factor | Managed Service | Self-Hosted |
|---|---|---|
| Operational burden | Low — provider handles patching, backups, failover | High — your team manages everything |
| Cost | 30-50% premium over self-hosted | Lower base cost, but add ops team time |
| Customization | Limited — provider controls configuration | Full control over every parameter |
| Vendor lock-in | High — migration is complex | None — portable across clouds |
| Scaling | Easy — click or API call | Manual — you manage replicas and sharding |
| Compliance | Provider certifications | You manage compliance yourself |
| Support | 24/7 from provider | Your team + community |
Managed Service Offerings
# PostgreSQL managed services
postgresql_managed:
aws:
service: Amazon RDS / Aurora PostgreSQL
features: "Multi-AZ, read replicas, automated backups, pg_upgrade"
pricing: "db.r6g.large ~$0.25/hr"
azure:
service: Azure Database for PostgreSQL
features: "Hyperscale (Citus), logical replication, threat protection"
pricing: "Standard_D2s_v3 ~$0.23/hr"
gcp:
service: Cloud SQL for PostgreSQL
features: "High availability, read replicas, maintenance window"
pricing: "db-custom-2-8192 ~$0.22/hr"
mongodb:
service: MongoDB Atlas
features: "Auto-scaling, global clusters, encryption at rest"
pricing: "M10 ~$0.08/hr"
redis:
service: Amazon ElastiCache / Azure Cache
features: "Auto-failover, backup, encryption"
pricing: "cache.r6g.large ~$0.20/hr"Managed services cost more per resource unit but save engineering time. A single database engineer costs more than the premium on managed services. For small teams, managed is almost always the right choice.
Self-Hosted on Kubernetes
- Full control over PostgreSQL configuration and extensions
- Custom replication topologies (multi-region, cascading)
- No vendor lock-in — portable across cloud providers
- Use database operators for automation (CloudNativePG, CrunchyData)
- Lower cost at scale (hundreds of instances)
- Compliance requirements that prohibit third-party data access
Cost Analysis
cost_model:
small_team:
team_size: 2 engineers
database_instances: 3
monthly_cost:
managed: # RDS
instances: "$1,800" # 3x db.r6g.large
operations: "$0" # included in premium
total: "$1,800"
self_hosted: # EKS + operator
instances: "$900" # 3x m6i.large EC2
storage: "$300" # EBS volumes
operations: "$5,000" # engineer time (~20 hrs/mo)
total: "$6,200"
large_team:
team_size: 10 engineers (dedicated SRE)
database_instances: 30
monthly_cost:
managed:
instances: "$18,000"
operations: "$0"
total: "$18,000"
self_hosted:
instances: "$9,000"
storage: "$3,000"
operations: "$2,000" # shared across 10 engineers
total: "$14,000"At small scale, managed services are cheaper when you factor in engineering time. At large scale (100+ instances), self-hosted becomes cheaper because the operational overhead is amortized across many instances.
Hybrid Approach
hybrid_strategy:
production_postgresql:
service: "RDS Multi-AZ"
reason: "Maximum reliability, minimal ops burden"
staging_development:
service: "Self-hosted on Kubernetes"
reason: "Cost savings, team learning"
redis_caching:
service: "ElastiCache"
reason: "Simple, no custom config needed"
redis_specialized:
service: "Self-hosted Redis Cluster"
reason: "Custom data structures, Lua scripts, non-standard config"
analytics:
service: "Self-hosted ClickHouse on Kubernetes"
reason: "Not available as managed, cost at scale"The hybrid approach uses managed services for standard workloads and self-hosted for specialized needs. This balances operational burden with flexibility. Many successful companies use this pattern.
Migration Path Between Options
- Managed to self-hosted: pg_dump/pg_restore, update connection strings
- Self-hosted to managed: create managed instance, replicate, cut over
- Cloud to cloud: logical replication, CDC, or application-level migration
- Always test migration in staging before production
- Keep the old system running during migration for rollback
It is easier to migrate from managed to self-hosted than the reverse. Start with managed services to minimize operational burden. If you outgrow managed services, you can always migrate to self-hosted with more data and better understanding of your requirements.
Database operations are complex. Every hour spent on database management is an hour not spent on product features. For most startups and small teams, the managed service premium is worth the engineering time saved.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.