Sparki Monetization Implementation Guide
Document ID: SPARKI-IMPLEMENTATION-001Version: 1.0
Date: 2025-12-04
Status: Developer Roadmap
Audience: Backend Engineers, DevOps
Executive Summary
This guide provides 8-week, step-by-step implementation of Sparki’s tiered monetization system. The implementation:- Preserves all existing Sparki functionality (no breaking changes)
- Runs alongside open-source code (billing is an optional add-on)
- Enables all three tiers (Community, Team, Pro, Enterprise)
- Integrates with Polar for payments
- Can be deployed incrementally (test → staging → production)
Phase 1: Preparation & Infrastructure (Weeks 1-2)
Week 1: Setup Polar Account & Database
1.1 Polar Account Setup (1 engineer, 2 hours)
- Create Polar.sh account at https://dashboard.polar.sh
- Create organization: “Sparki”
- Create API tokens:
- Organization Access Token (OAT) for backend API calls
- Secret webhook key for webhook validation
- Store in vault:
1.2 Create Polar Products (1 engineer, 3 hours)
1.3 Database Schema Migration (1 engineer, 4 hours)
File:migrations/001_monetization_schema.sql
Week 2: Load Tier Configuration
2.1 Tier Configuration YAML (1 engineer, 2 hours)
File:config/tiers.yaml (as per SPARKI_POLAR_INTEGRATION_TECHNICAL.md §2.2)
2.2 Load Configuration on Startup (1 engineer, 3 hours)
File:internal/config/loader.go
2.3 Infrastructure Setup (DevOps, 2 hours)
- PostgreSQL 14+ with TimescaleDB extension
- Redis 7+ for caching
- Prometheus for metrics
- Create vault/secrets for Polar credentials
Phase 2: Tier Validation System (Weeks 3-4)
Week 3: API Gateway Middleware
3.1 Tier Validation Middleware (2 engineers, 5 hours)
File:internal/middleware/tier_validator.go
3.2 Register Middleware in Router (1 engineer, 2 hours)
File:cmd/api/main.go
Week 4: Quota Enforcement in Handlers
4.1 Private Projects Endpoint (1 engineer, 3 hours)
File:internal/handlers/projects.go
4.2 Concurrent Jobs Endpoint (1 engineer, 3 hours)
File:internal/handlers/builds.go
Phase 3: Usage Tracking (Week 5)
5.1 Usage Service (1 engineer, 3 hours)
File:internal/services/usage_service.go
5.2 Instrumentation (2 engineers, 5 hours)
Add usage recording to key handlers:5.3 Nightly Aggregation Job (1 engineer, 4 hours)
File:internal/jobs/meter_sync.go
Phase 4: Polar Integration (Weeks 6-7)
Week 6: Checkout & Subscription
6.1 Polar Client (1 engineer, 3 hours)
File:pkg/polar/client.go
6.2 Billing Handler (1 engineer, 3 hours)
File:internal/handlers/billing.go
Week 7: Webhooks & Event Handling
7.1 Webhook Handler (1 engineer, 4 hours)
File:internal/handlers/webhooks.go
7.2 Register Webhook Endpoint (1 engineer, 1 hour)
File:cmd/api/main.go
Phase 5: Monitoring & Observability (Week 8)
8.1 Prometheus Metrics (1 engineer, 3 hours)
File:internal/metrics/collector.go
8.2 Grafana Dashboard (DevOps, 2 hours)
JSON dashboard config tracking:- Active subscriptions by tier (gauge)
- New subscriptions (counter)
- Failed checkouts (counter)
- Webhook latency (histogram)
- Failed webhooks (counter)
- MRR trend (gauge)
8.3 Alerting (DevOps, 2 hours)
PagerDuty alerts:- Polar API down >5 min → P1
- Webhook failures >10% → P2
- MRR decline >5% MoM → P3
Testing Checklist
Unit Tests (2 engineers, 5 hours)
Integration Tests (2 engineers, 5 hours)
- Signup → free tier → works
- Checkout → Polar → webhook → tier upgrade
- API call as team → succeeds
- API call as community on private → fails
- Usage recorded → nightly sync → Polar
- Cancel subscription → webhook → tier downgrade
Manual Testing (1 engineer, 3 hours)
-
Sandbox Environment
- Deploy to staging
- Test full flow with Polar sandbox
- Verify webhook handling
-
Production Dry-Run
- Deploy with feature flag OFF
- Enable for 1% of users
- Monitor metrics
- Gradually roll out to 100%
Deployment Checklist
Pre-Deployment (Day Before)
- Database migrations tested on production backup
- Polar webhook secret loaded in vault
- Tier configuration YAML deployed
- Metrics collectors registered
- Alerting rules configured in PagerDuty
- Runbook written for incident response
Deployment
Post-Deployment
- Check dashboard for errors
- Verify Polar integration working
- Test checkout flow in production
- Monitor billing metrics (MRR, subscriptions)
- Check webhook lag <5 seconds
Rollback Plan
If issues occur:Success Metrics
By end of Week 8: ✅ Functionality- 3 tiers fully implemented (Community, Team, Pro)
- All endpoints enforce tier quotas
- Usage tracking records all metrics
- Polar integration working end-to-end
- Webhooks processing reliably
- API latency <100ms (tier validation overhead <5ms)
- Webhook processing <5s
- Nightly meter sync completes <1 hour
- 99.9% webhook delivery (Polar ensures)
- 100% meter sync success (retry logic)
- Zero data loss (transactional updates)
- All metrics exported to Prometheus
- Grafana dashboard complete
- Alerts configured + tested
- Runbook updated
Continuation: Beyond Week 8
Once monetization is deployed:-
Marketing Launch (Week 9-10)
- Launch pricing page
- Email existing users
- Blog post on sustainable open-source
- Demo video
-
Customer Success (Week 11+)
- Onboarding flow for paid tiers
- Team collaboration features
- Advanced security scanning
- Support escalation for Enterprise
-
Optimization (Month 3+)
- Analyze churn patterns
- Optimize tier boundaries
- Build usage-based analytics dashboard
- Prepare for Sparki 2.0 features (on-prem, advanced deploy)
Conclusion
This 8-week plan makes Sparki a sustainable, profitable open-source platform while keeping the core forever free. The modular design allows iterative deployment, testing at each phase, and rollback if needed. Key success factors:- Team buys in to sustainable monetization
- Testing is thorough (unit + integration + manual)
- Deployment is gradual (1% → 10% → 100%)
- Monitoring is real-time (catch issues early)
- Communication is transparent (users understand tiers)