Skip to main content

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

AspectDetails
DatabasePostgreSQL 15
ORMPrisma 6.18.0
PostgreSQL Features Used14+ ENUMs, JSONB fields, Array types
Schema Complexity45+ tables, 50+ indexes
Multi-tenancyOrganization-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​

FeatureDetails
Pricing ModelTrue 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 Tier100 CU-hours/month, 0.5GB storage
Scale-to-ZeroYes (5 min idle default)
Cold Start500ms - 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​

FeatureDetails
Pricing ModelInstance-based (always-on)
Free TierNano instance, 500MB storage
Pro Plan$25/month + $10 compute credit
Scale-to-ZeroNo (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​

FeatureDetails
Pricing ModelUsage-based (CPU/RAM hours)
Free Tier30-day trial only
Hobby Plan$5/month + $5 credit
Scale-to-ZeroPartial (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​

FeatureDetails
Pricing ModelACU-based (per second)
Minimum0.5 ACU = ~$43.80/month minimum
Scale-to-ZeroNo (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)​

FeatureStatus
Custom ENUMsFully supported
JSONB columnsFully supported
Array typesFully supported
GIN indexesFully supported
Cascading deletesFully supported
PostgreSQL 15Supported (14, 15, 16, 17, 18)

Prisma Integration (Excellent)​

AspectStatus
Prisma MigrateWorks with single connection URL
Connection poolingBuilt-in PgBouncer
Prisma ClientFull support
Prisma StudioWorks

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​

  1. Cold start latency: First query after idle may take 500ms-2s
  2. Connection timeouts: May need to increase Prisma pool_timeout
  3. Unlogged tables: Behavior differs (truncated on scale-to-zero)
  4. Idle connections: Auto-closed after inactivity

Cost Estimation​

Scenario: Development/Staging Environment​

  • Idle 80% of the time
  • Active 4 hours/day with light usage
ProviderEstimated 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
ProviderEstimated 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:

  1. True pay-per-use: Scale-to-zero means $0 when idle
  2. Full compatibility: All PostgreSQL features you use are supported
  3. Excellent Prisma support: Simplified setup, single URL
  4. Cost control: Set autoscaling limits as cost ceiling
  5. Database branching: Great for dev/staging environments
  6. Strong backing: $1B Databricks acquisition ensures longevity

Migration Steps (DigitalOcean to Neon)​

Phase 1: Setup​

  1. Create Neon account and project (PostgreSQL 15)
  2. Choose Launch plan ($19/month) for production
  3. Set autoscaling limit (e.g., 2 CU max) for cost control

Phase 2: Schema Migration​

  1. Connect Prisma to Neon using new DATABASE_URL
  2. Run npx prisma migrate deploy to apply all migrations
  3. Verify schema matches current database

Phase 3: Data Migration​

  1. Export from DigitalOcean: pg_dump -h <host> -U <user> -d stemblock_db > backup.sql
  2. Import to Neon: psql -h <neon-host> -d <db> < backup.sql
  3. Or use Neon's import tool for larger databases

Phase 4: Application Update​

  1. Update DATABASE_URL in environment (local, staging, production)
  2. Increase Prisma connection timeout if needed: ?connection_limit=5&pool_timeout=30
  3. Deploy application

Phase 5: Validation & Cutover​

  1. Run application tests against Neon
  2. Monitor cold start latency (typically 500ms-2s)
  3. Cut over production when confident
  4. Keep DigitalOcean database for 1 week as rollback option
  5. Delete DigitalOcean database after validation

Files to Modify​

  • stemblockai-backend/.env - Update DATABASE_URL
  • stemblockai-backend/.env.production - Update DATABASE_URL
  • Any CI/CD secrets storing database connection string

Sources​