Preview Environments using Neon, Kubernetes, and Argo CD
Per-pull-request preview environments can be built by pairing Neon's copy-on-write Postgres branches with an Argo CD ApplicationSet using the pullRequest generator, which deploys a Helm chart into a namespace per PR. A GitHub Actions workflow builds and pushes the container image, creates a Neon branch and compute via create-branch-action, then uses the argocd CLI to set the database URL and image tag on the PR's Application. It also comments the preview URL on the PR. Setting these parameters imperatively departs from strict GitOps but is a pragmatic tradeoff when values aren't known ahead of time.
Related posts
- A database for every preview environment using Neon, GitHub Actions, and Vercel
Neon mediumAdept
Neon's copy-on-write branching can give every pull request its own production-like Postgres database, avoiding the bottlenecks of shared staging or shared preview databases. Branches are isolated, are created in about a second regardless of database size, and bill only for unique data. A GitHub Actions pipeline creates a Neon branch per PR, runs Prisma migrations against it, deploys a Vercel preview wired to that branch, and comments the URLs on the PR. Merging applies migrations to the primary branch, deploys to production and deletes the preview branch.
- Fullstack preview environments using Neon and Qovery
Neon mediumAdept
Each Qovery preview environment can get its own isolated Postgres database by using a Qovery lifecycle job that creates a copy-on-write Neon branch on the environment's Start event and deletes it on Delete. A Docker image bundles the Neon CLI and two shell scripts. create-branch.sh creates a branch named after QOVERY_ENVIRONMENT_NAME and writes direct and pooled connection strings to /qovery-output/qovery-output.json, so other services receive them as environment variables. delete-branch.sh looks up the branch ID through the Neon API and deletes it. This sidesteps the conflicts of a shared preview database and the slow provisioning, stale seed scripts and privacy issues of copying production data.
- Behind Modem.dev’s Product Velocity
Neon mediumAdept
Modem, a startup building an AI agent that centralizes user feedback from Slack, Discord and GitHub, uses Neon Postgres branching as its development workflow. Every PR with a migration gets its own database branch, where the migration is applied and a schema diff is posted to the PR. The process is repeated against a fresh branch at merge time to catch conflicting migrations, and each Vercel preview runs on an ephemeral branch with automatic cleanup. Two practical tips: script branching through the Neon CLI so coding agents can drive it, and tag OAuth refresh tokens with the originating branch so preview environments can't invalidate production tokens.
- A branch-first dev loop for Neon: link, checkout and env pull
Neon mediumAdept
Neon's CLI adds three commands for branch-first Postgres development. `neon link` binds a workspace to a project and branch via a git-ignored `.neon` file. `neon checkout` creates or switches database branches, much like `git checkout -b`. `neon env pull` writes only the Neon-managed connection strings and service secrets for the current branch into `.env`. Link and checkout run env pull automatically, which suits coding agents that need an isolated database per feature. Teams that keep secrets off disk can pass `--no-env-pull` and inject env at runtime with `@neondatabase/env` (`neon-env run`, `fetchEnv`) or export it into varlock.
- Branching Postgres databases with the Neon API
Neon mediumAdept
Neon branches are copy-on-write clones of a Postgres database that can be created and deleted through the Neon API, giving CI pipelines an isolated copy of production data for end-to-end tests. Two experimental GitHub Actions, neondatabase/create-branch-action and neondatabase/delete-branch-action, wrap the API. A sample pull-request workflow creates a branch from a parent branch, runs the test steps, then deletes the branch. The actions were beta at the time and still being hardened for production use.