Database Migration Research: Pay-Per-Use Options
Executive Summary
Recommendation: Neon is the best fit for StemBlock AI's pay-per-use requirements.
Your current PostgreSQL 15 + Prisma setup is fully compatible with Neon. Key benefits:
- True scale-to-zero (no charges when idle)
- Full PostgreSQL compatibility (all your ENUMs, JSONB, arrays work)
- Excellent Prisma integration (simplified to single connection URL)
- Storage: $0.35/GB-month (down from $1.75 after Databricks acquisition)
- Compute: ~$0.14-0.22/CU-hour
Current Database Setup (StemBlock AI)
| Aspect | Details |
|---|---|
| Database | PostgreSQL 15 |
| ORM | Prisma 6.18.0 |
| PostgreSQL Features Used | 14+ ENUMs, JSONB fields, Array types |
| Schema Complexity | 45+ tables, 50+ indexes |
| Multi-tenancy | Organization-level isolation |
Critical PostgreSQL Features Your App Uses:
- Custom ENUMs (UserRole, SubmissionStatus, SubscriptionTier, etc.)
- JSONB columns (ai_feedback, settings, metadata)
- Array types (daysOfWeek, focusSkills, tags)
- Cascading deletes
- Composite indexes
Provider Comparison
1. Neon (Recommended)
| Feature | Details |
|---|---|
| Pricing Model | True pay-per-use with scale-to-zero |
| Compute | $0.14-0.22/CU-hour (1 CU = 1 vCPU + 4GB RAM) |
| Storage | $0.35/GB-month |
| Free Tier | 100 CU-hours/month, 0.5GB storage |
| Scale-to-Zero | Yes (5 min idle default) |
| Cold Start | 500ms - few seconds |
Pros:
- Zero cost when database is idle
- Full PostgreSQL compatibility (14-18 supported)
- Native Prisma integration (single connection URL)
- Database branching for dev/staging
- Acquired by Databricks ($1B) - strong backing
Cons:
- Cold start latency on first connection after idle
- Unlogged tables don't persist across compute restarts
Pricing Tiers:
- Free: $0 (100 CU-hours, 0.5GB)
- Launch: $19/month base + usage
- Scale: $69/month base + usage
- Business: $700/month base + usage
2. Supabase
| Feature | Details |
|---|---|
| Pricing Model | Instance-based (always-on) |
| Free Tier | Nano instance, 500MB storage |
| Pro Plan | $25/month + $10 compute credit |
| Scale-to-Zero | No (compute always running) |
Pros:
- Full backend-as-a-service (auth, storage, real-time)
- Good PostgreSQL compatibility
Cons:
- No scale-to-zero - pay even when idle
- Less cost-effective for variable workloads
- Would need to migrate auth (you already have JWT)
3. Railway
| Feature | Details |
|---|---|
| Pricing Model | Usage-based (CPU/RAM hours) |
| Free Tier | 30-day trial only |
| Hobby Plan | $5/month + $5 credit |
| Scale-to-Zero | Partial (still charged for RAM) |
Pros:
- Simple deployment
- Usage-based billing
Cons:
- No permanent free tier
- Less PostgreSQL-focused than Neon
- No true scale-to-zero for databases
4. Amazon Aurora Serverless v2
| Feature | Details |
|---|---|
| Pricing Model | ACU-based (per second) |
| Minimum | 0.5 ACU = ~$43.80/month minimum |
| Scale-to-Zero | No (removed in v2) |
Cons:
- Minimum monthly charge ~$44
- Cannot scale to zero (v1 could, but deprecated Dec 2024)
- More complex setup
Neon Compatibility Analysis
PostgreSQL Features (All Supported)
| Feature | Status |
|---|---|
| Custom ENUMs | Fully supported |
| JSONB columns | Fully supported |
| Array types | Fully supported |
| GIN indexes | Fully supported |
| Cascading deletes | Fully supported |
| PostgreSQL 15 | Supported (14, 15, 16, 17, 18) |
Prisma Integration (Excellent)
| Aspect | Status |
|---|---|
| Prisma Migrate | Works with single connection URL |
| Connection pooling | Built-in PgBouncer |
| Prisma Client | Full support |
| Prisma Studio | Works |
Recent improvement: No longer need separate direct/pooled URLs - single URL works for everything.
Migration Considerations
Low Risk Factors
- Standard PostgreSQL - no proprietary features
- All features used are native PostgreSQL (not cloud-specific)
- Prisma handles connection management
- Neon supports same PostgreSQL version (15)
Things to Watch
- Cold start latency: First query after idle may take 500ms-2s
- Connection timeouts: May need to increase Prisma
pool_timeout - Unlogged tables: Behavior differs (truncated on scale-to-zero)
- Idle connections: Auto-closed after inactivity
Cost Estimation
Scenario: Development/Staging Environment
- Idle 80% of the time
- Active 4 hours/day with light usage
| Provider | Estimated Monthly Cost |
|---|---|
| Neon | $5-15 (only pay when active) |
| Supabase | $25+ (always-on Pro) |
| DigitalOcean (Current) | $50-100+ (fixed instance) |
Scenario: Production with Variable Load
- 8 hours moderate activity/day
- Weekend traffic 50% lower
| Provider | Estimated Monthly Cost |
|---|---|
| Neon Scale | $69 + ~$50-80 compute = $120-150 |
| Supabase Team | $599 (likely overkill) |
| Aurora Serverless | $44 minimum + usage |
Recommendation
Migrate to Neon for these reasons:
- True pay-per-use: Scale-to-zero means $0 when idle
- Full compatibility: All PostgreSQL features you use are supported
- Excellent Prisma support: Simplified setup, single URL
- Cost control: Set autoscaling limits as cost ceiling
- Database branching: Great for dev/staging environments
- Strong backing: $1B Databricks acquisition ensures longevity
Migration Steps (DigitalOcean to Neon)
Phase 1: Setup
- Create Neon account and project (PostgreSQL 15)
- Choose Launch plan ($19/month) for production
- Set autoscaling limit (e.g., 2 CU max) for cost control
Phase 2: Schema Migration
- Connect Prisma to Neon using new DATABASE_URL
- Run
npx prisma migrate deployto apply all migrations - Verify schema matches current database
Phase 3: Data Migration
- Export from DigitalOcean:
pg_dump -h <host> -U <user> -d stemblock_db > backup.sql - Import to Neon:
psql -h <neon-host> -d <db> < backup.sql - Or use Neon's import tool for larger databases
Phase 4: Application Update
- Update
DATABASE_URLin environment (local, staging, production) - Increase Prisma connection timeout if needed:
?connection_limit=5&pool_timeout=30 - Deploy application
Phase 5: Validation & Cutover
- Run application tests against Neon
- Monitor cold start latency (typically 500ms-2s)
- Cut over production when confident
- Keep DigitalOcean database for 1 week as rollback option
- Delete DigitalOcean database after validation
Files to Modify
stemblockai-backend/.env- Update DATABASE_URLstemblockai-backend/.env.production- Update DATABASE_URL- Any CI/CD secrets storing database connection string