Going to Production
This guide consolidates all the services and configurations you’ve used (Supabase, Stripe, Resend, Upstash, PostHog) and walks through final steps for deploying and verifying your application in a production environment.
1. Overview
Before moving to production, ensure you have:
- Development Environment fully configured and tested.
- Staging Environment (optional but recommended) where you can verify new features/integrations without impacting real users.
- Production Credentials for each service (Supabase, Stripe, Resend, Upstash, PostHog).
2. Set Up Production Environment
-
Hosting Provider
- Choose a hosting solution (e.g., Vercel, AWS, DigitalOcean) that supports your Next.js application.
- Consider how you’ll handle SSL, load balancing, and autoscaling (if necessary).
-
Production Domain
- Secure your domain and configure DNS records (e.g.,
CNAMEorArecords) to point to your hosting provider. - Obtain and install an SSL certificate (often automated via your host).
- Secure your domain and configure DNS records (e.g.,
-
Version Control & CI/CD
- Set up continuous integration and delivery so each new push to
mainor areleasebranch triggers a build/deployment pipeline.
- Set up continuous integration and delivery so each new push to
3. Configure Environment Variables
Create a new environment (e.g., .env.production) or use your hosting provider’s environment variable manager. Make sure to include production keys:
-
Supabase
NEXT_PUBLIC_SUPABASE_URLNEXT_PUBLIC_SUPABASE_ANON_KEYSUPABASE_SERVICE_ROLE_KEY(only used server-side)
-
Stripe
STRIPE_PUBLIC_KEY=pk_live_...STRIPE_SECRET_KEY=sk_live_...STRIPE_WEBHOOK_SECRET=whsec_live_...
-
Resend
RESEND_API_KEY- Any relevant audience or domain IDs.
-
Upstash
UPSTASH_REDIS_REST_URLUPSTASH_REDIS_REST_TOKEN
-
PostHog
NEXT_PUBLIC_POSTHOG_KEYNEXT_PUBLIC_POSTHOG_HOST(e.g.,https://app.posthog.comor your self-hosted URL)
Important: Never commit sensitive credentials to version control. Use your hosting platform’s secure environment variable settings or secret manager.
4. Configure External Services
4.1 Supabase
- Production Project: In your Supabase dashboard, create or identify a project specifically for production use.
- Database Migrations: Make sure your tables and data structure match what you need in production. Apply any migrations from dev/staging.
- RLS Policies: Confirm that row-level security (RLS) policies are set correctly for your production environment (e.g., restricting data only to authenticated users).
4.2 Stripe
- Switch Stripe to “Live Mode” in the Stripe Dashboard.
- Verify your Live Keys (
pk_live_...andsk_live_...). - Add a live webhook endpoint (
https://yourdomain.com/api/webhooks/stripe) and set the correct webhook events. - Test a small real transaction (using a real card or Stripe test card in live mode with minimal charge) to ensure the flow works.
4.3 Resend
- Ensure you’re using a custom sending domain in Resend if you want brand-friendly emails (e.g.,
noreply@mydomain.com). - Verify DNS (SPF, DKIM) as recommended by Resend for better deliverability.
- Monitor your email sending limits and handle bounce or unsubscribe logic if applicable.
4.4 Upstash (Redis)
- Production Redis Database: Use a dedicated database or separate namespace for production rate limiting and caching.
- Update the
UPSTASH_REDIS_REST_URLandUPSTASH_REDIS_REST_TOKENin your production environment. - Confirm your rate limiting configuration meets your production traffic expectations (e.g.,
200 requests / minuteinstead of100 / 15 minutes, etc.).
4.5 PostHog
- In your PostHog dashboard, create or designate a production project to track real user events separately from development/staging data.
- Update
NEXT_PUBLIC_POSTHOG_KEYandNEXT_PUBLIC_POSTHOG_HOST. - Double-check compliance with privacy laws if you’re tracking user behavior in production (e.g., GDPR).
5. Build & Deploy
- Install Dependencies:
npm installoryarn installin the production build environment. - Build:
npm run buildoryarn build. - Start Server (if self-hosting) or let your hosting platform handle the Next.js build process (e.g., Vercel auto-deployment).
- Verify Logs: Check build logs for errors or missing environment variables.
6. Post-Deployment Checks
After the application is up and running at https://yourdomain.com:
- Smoke Test: Perform basic actions like sign up, log in, view profiles, etc.
- Stripe Webhooks: Create a test charge in live mode to see if your webhook logic processes events correctly (e.g., subscription updates).
- Email Delivery: Trigger an email (e.g., password reset, welcome email) to confirm Resend is sending from your production domain.
- Rate Limiting: Confirm you can still make repeated API requests without being locked out incorrectly (use a staging approach if possible).
- Analytics: Check PostHog to see if pageviews/events from your domain are recorded.
- Database: Ensure data is flowing into your production Supabase project, and RLS policies aren’t blocking legitimate user actions.
7. Monitoring & Maintenance
- Logs & Error Tracking: Use a service like Sentry or your hosting provider’s logs to track errors in real time.
- Performance Monitoring: Keep an eye on response times, CPU/memory usage (e.g., via your hosting provider’s dashboard).
- Security Updates: Regularly update dependencies and patches.
- Backup & Disaster Recovery: Enable backups for your Supabase database, keep versions for your code, and have a plan for key rotations (Stripe, Resend, Upstash, PostHog) if credentials are compromised.
- Scaling: If traffic grows, ensure your hosting plan, database, and Redis usage can scale accordingly.
Conclusion
By carefully migrating your environment variables, configuring all external services in their production modes, and verifying functionality post-deployment, you’ll have a robust, production-ready stack. Always keep an eye on logs, metrics, and user feedback to catch issues early and ensure a smooth user experience.
Congratulations on reaching production! If you encounter specific issues, refer back to each service’s dedicated documentation or your detailed setup guides for debugging and best practices.
Happy launching!