Vercel's default deployment is simple: connect your Git repository, push code, and it's live. But as your product grows, you need more control.
July 6, 2024 9 min read
# Vercel Deployment: Beyond the Basics
Slug: vercel-deployment-beyond-basics
Date: 2024-09-27
Tag: Tech Stack
Meta Description: Advanced Vercel deployment patterns for startups. Preview environments, environment variables, edge functions, and optimization strategies beyond the basics.
---
Vercel's default deployment is simple: connect your Git repository, push code, and it's live. That basic workflow gets you surprisingly far.
But as your product grows, you need more control. Preview environments for client demos. Environment variables that don't leak between environments. Edge functions for low-latency APIs. Monitoring for production issues.
This post covers the Vercel patterns we use after the initial setup. Practical configurations that make deployment smoother as your startup scales.
Preview Deployments for Real-World Use
Every pull request on Vercel automatically gets a preview deployment. The URL looks like your-project-abc123-yourteam.vercel.app.
That's useful for code review. With some configuration, it becomes useful for client demos, QA testing, and team collaboration.
Stable Preview URLs
The default preview URL changes with every deployment. For sharing with clients or external testers, you want stable URLs.
Branch-specific URLs: Enable branch subdomains in Project Settings > Domains. The branch becomes .
Stop planning and start building. We turn your idea into a production-ready product in 6-8 weeks.
staging
staging.your-project.vercel.app
This works for:
Staging environment: Shared URL for QA and client review
Feature branches: Stable URLs for long-running features
Demo environments: Persistent URLs for sales demonstrations
Preview Environment Variables
Preview deployments need their own environment variables. You don't want previews hitting production databases or payment processors.
In Project Settings > Environment Variables, you can scope variables to:
Production: Only the production deployment
Preview: All preview deployments
Development: Local development (vercel dev)
Common pattern:
This prevents accidents. Your preview deployment can't accidentally charge a real credit card or write to production data.
Preview Protection
By default, preview deployments are public. Anyone with the URL can access them.
For products with sensitive data or unreleased features, enable Vercel Authentication:
Project Settings > Deployment Protection
Enable for Preview deployments
Require Vercel login or password
Now only team members (or those with the password) can access previews. Share with clients using the password protection option.
Environment Variable Management
Environment variables on Vercel deserve more attention than most teams give them.
The Right Structure
Organize variables by purpose:
Secrets (API keys, database URLs):
Configuration (feature flags, service URLs):
Build-time (analytics, error tracking):
Using NEXT_PUBLIC Correctly
Variables prefixed with NEXT_PUBLIC_ are embedded in the client-side JavaScript bundle. They're visible to anyone inspecting your code.
Safe to expose:
Analytics keys (PostHog, Amplitude)
Public API URLs
Feature flags
Error tracking DSNs
Never expose:
Database credentials
Payment processor secrets
Authentication secrets
Internal service URLs
Environment Variable Encryption
Vercel encrypts environment variables at rest. But some teams want additional protection for highly sensitive values.
Options:
Vercel Secrets: Recommended for most teams
External secret managers: AWS Secrets Manager or HashiCorp Vault for enterprise requirements
Encrypted environment variables: Encrypt values before storing, decrypt at runtime
For most MVPs, Vercel's built-in encryption is sufficient.
Syncing with Local Development
The Vercel CLI can pull environment variables to your local machine:
This creates a .env.local file with all Development-scoped variables. Faster than copying values manually and reduces the chance of typos.
Add .env.local to .gitignore—never commit environment files.
Edge Functions and Middleware
Edge Functions run on Vercel's global network, close to users. For latency-sensitive operations, they're significantly faster than traditional serverless functions.
When to Use Edge Functions
Authentication checks: Validate sessions before the request reaches your application.
This runs at the edge—before the page even starts rendering. Unauthorized users get redirected in milliseconds.
Geographic routing: Route users to different content based on location.
A/B testing: Assign users to test groups before page load.
Edge Function Limitations
Edge Functions run in a limited environment:
No Node.js APIs: Use Web APIs instead
Size limits: 1MB compressed code size
Execution time: 30 seconds maximum
Memory: Limited compared to serverless
For database queries, heavy computation, or long-running tasks, use regular API routes.
Production issues happen. Vercel makes rollback straightforward.
Instant Rollbacks
Every deployment is immutable. Rolling back means pointing traffic to a previous deployment:
Go to Deployments in the dashboard
Find the last working deployment
Click the three dots menu > Promote to Production
Traffic switches immediately. No rebuild required.
Deployment Aliases
For critical releases, create a deployment alias before promoting:
If the new release has issues, switch stable.yourproduct.com back to the previous deployment instantly.
Canary Deployments
Route a percentage of traffic to new deployments before full rollout:
Monitor errors and performance on the canary before expanding.
Cost Management
Vercel pricing scales with usage. Understanding the cost drivers helps manage spend.
Key Cost Factors
Bandwidth: Data transferred to users
Function execution: Time and invocations for API routes
Edge middleware: Invocations for middleware functions
Build minutes: Time spent building deployments
Optimization Strategies
Reduce bandwidth:
Use Vercel's Image Optimization for automatic resizing
Enable compression (on by default)
Implement aggressive caching headers
Reduce function execution:
Cache responses where possible
Move static data to edge caching
Optimize function cold starts
Reduce edge middleware:
Limit middleware to paths that need it
Keep middleware logic minimal
Spend Notifications
Set spending alerts in Account Settings > Billing. Get notified before unexpected costs.
When to Consider Alternatives
At very high scale (millions of daily active users, terabytes of bandwidth), self-hosted or alternative platforms might be more cost-effective.
For MVP-stage startups, Vercel's pricing is usually reasonable compared to the engineering time saved.
Integration with Our Stack
We use Vercel with Next.js and Convex. Some integration patterns:
Convex Deployment
Convex has its own deployment process. Coordinate with Vercel:
Vercel runs npm run build during deployment, which deploys Convex functions before building Next.js.
Preview Environments with Convex
For preview deployments to work with Convex, you need preview-specific Convex deployments:
Create a preview Convex deployment
Set CONVEX_URL for Preview environment in Vercel
Preview deployments use isolated data
Alternatively, all previews can share a staging Convex deployment for simpler setup.
Authentication Integration
Clerk or WorkOS webhooks need to reach your application:
Configure auth providers to call different webhook URLs based on environment.
Key Takeaways
Beyond basic deployment, Vercel provides tools for serious production use:
Preview environments: Configure for client demos and team collaboration
Environment variables: Scope correctly, never expose secrets
Edge functions: Use for low-latency operations, not heavy computation
Monitoring: Add error tracking and structured logging
Build optimization: Keep deploys fast as the codebase grows
Rollbacks: Know how to recover quickly when issues arise
The patterns here scale from MVP to production traffic. Start simple, add complexity as needed. For the complete deployment workflow, see CI/CD Explained: Why It Matters.
---
At NextBuild, we deploy all projects on Vercel with these patterns built in. If you're planning a web application and want production-ready deployment from day one, let's discuss your project.
Document automation can cut drafting time from 3 hours to 15 minutes. But most MVPs fail by building too much too soon. Here are the 5 features that actually matter.
export function middleware(request: NextRequest) { const hostname = request.headers.get("host"); const subdomain = hostname?.split(".")[0]; if (subdomain && subdomain !== "www" && subdomain !== "yourproduct") { // Route to tenant-specific content return NextResponse.rewrite( new URL(`/tenants/${subdomain}${request.nextUrl.pathname}`, request.url), ); }}
typescript
// sentry.client.config.tsimport * as Sentry from "@sentry/nextjs";Sentry.init({ dsn: process.env.NEXT_PUBLIC_SENTRY_DSN, tracesSampleRate: 0.1, // 10% of transactions for performance monitoring});